Here's an example of the syntax I have in mind in its simplest form. It strongly resembles a Dim/Var declaration.
Code: |
Class Pen
Property Color As UInt End Class Pen #pen #pen Color = &HFF0000 End |
You can associate getter and setter methods with a property by using the ON keyword.
Code: |
Property name
[ On Get [statements] ] [ On Set param [statements] ] End Property |
Let's say we want to prevent invalid values being assigned to Color.
Code: |
Class Pen
Property Color As UInt On Set value value And= &HFFFFFF End Property End Class |
If you are familiar with VB.NET, the following is functionally equivalent to the above code.
Code: |
Public Class Pen
Private _color As Integer Public Property Color() As Integer Get Return _color End Get Set (ByBal value As Integer) _color = value And &HFFFFFF End Set End Property End Class |
Here are some things to notice:
- VF's properties will allocate a variable for you.
- VF's properties are always public.
- VF's use of "Get" and "Set" do not represent keywords. They are simply labels that can be anything you want.
- VF's setter method assumes its parameter has the same type as the property itself.
- VF's getter and setter are simply guard clauses. They do not explicitly return or modify the underlying variable, but instead can prevent or override the default behavior.