Navigation: Clarion.Net (Clarion#) > Clarion# Language Extensions > CLASS attributes >====== PROPERTY (class specific private property) ====== | |
label | PROPERTY, datatype | ,PROTECTED | | | ,SETONLY | |
| ,GETONLY | | ||
| INLINE | | ||
| GETTER | | ||
CODE<; get method code > | ||
| SETTER | | ||
CODE<; set method code > | ||
| END| |
label | The label name of the property |
PROPERTY | Attribute assigned to any data type in a CLASS that restricts access to the data through appropriate GET (getter) and SET (setter) methods. |
datatype | The data type of the property. |
PROTECTED | Set PROPERTY private to CLASS or derived CLASS |
SETONLY | Marks PROPERTY with write-only access (no getter is provided for the property). |
GETONLY | Marks properties with read-only access (no setter is provided for the property) |
INLINE | Allows the Getter and Setter PROPERTY source to be defined within the CLASS. An INLINE statement must be terminated with an END. |
GETTER | Marks source that follows it as used in the Getter PROPERTY method |
SETTER | Marks source that follows it as used in the Setter PROPERTY method |
In any CLASS, a PROPERTY is a specific attribute applied to a data type. This makes the data type PRIVATE by default, and access to the data type is read and written to by appropriate GET (getter) and SET(setter) property methods. Optionally, these getter and setter methods can be added inline to the CLASS.
A GET or SET property method (or accessor) without a protection level automatically uses the protection level of the property. If you explicitly specify a protection level on an accessor, it must be more secure than the property itself.
If the setter and getter are not INLINE, and allowed by the PROPERTY, the name of the methods implementing the setter/getter must use the following naming convention:
Getter:
GET_<;name of property>
Setter:
SET_<;name of property>
Example:
MyClass CLASS
AgeType STRING(10), PRIVATE
AgeValue LONG, PRIVATE
AGE PROPERTY, LONG
END
MyClass.GET_AGE PROCEDURE()
CODE
RETURN SELF.AgeValue
MyClass.SET_AGE PROCEDURE(long pValue)
CODE
SELF.AgeValue = pValue
CASE SELF.AgeValue
OF 0 to 3
SELF.AgeType = 'Baby'
OF 4 to 13
SELF.AgeType = 'Kid'
OF 14 to 18
SELF.AgeType = 'Teenager'
ELSE
SELF.Agetype = 'Adult'
END
You can also add the appropriate GET and SET property methods using INLINE:
Example:
MyClass CLASS
AgeType STRING(10), PRIVATE
AgeValue LONG, PRIVATE
AGE PROPERTY, LONG
INLINE
GETTER
CODE
RETURN SELF.AgeValue
SETTER
CODE
SELF.AgeValue = pValue
CASE SELF.AgeValue
OF 0 to 3
SELF.AgeType = 'Baby'
OF 4 to 13
SELF.AgeType = 'Kid'
OF 14 to 18
SELF.AgeType = 'Teenager'
ELSE
SELF.Agetype = 'Adult'
END
END !INLINE definition
END !PROPERTY definition
END !CLASS definition
Using either technique above, the GET/SET methods are implied, and used through the order of assignment:
MyClass.Age = MyValue !Assigns value using Setter Code (if present)
MyValue = MyClass.Age !Assigns value using Getter Code (if present)
The implicit VALUE parameter is available in SETTER (as it is in the SET_<;name of property> variant). A PROPERTY construct that uses an INLINE structure requires an END terminator.
You can add any code you require into the SET and GET methods, and you can optionally specify data. For example, you can validate the setter values (i.e. rule: can't set value of credit limit > 1000 if a customer account is less then 30 days old),
You can also modify the getter value returned, or get it from some entity (a file, queue, etc). For example, the getter method for a TotalBalanceDue property could read thru a file to return the total for all open invoices.
Another reason to use these methods involves the data binding to controls. the data binding methods reflect over an object and look for properties rather than just public fields
There is no advantage using the standard method definition over the INLINE technique. It is strictly a matter of your own programming style.
See Also: INLINE