To design a VB .NET property you have to design an attribute with the <<Property>> stereotype, another attribute with the <<PropertyImplementation>> stereotype is automatically created, it is displayed with an underscore sign in the list of attributes. The corresponding getter and setter operations are also automatically created.
You can get rid of the implementation attribute.
If you remove the getter operation, the ReadOnly keyword is automatically generated. If you remove the setter operation, the WriteOnly keyword is automatically generated. If you remove both getter and setter operations, the attribute no longer has the <<Property>> stereotype.
When you define a <<Property>> attribute, the attribute changeability and the getter/setter operations are tightly related as explained in the following table:
Operations |
Property attribute changeability |
---|---|
If you keep both getter and setter operations |
Property is Changeable |
If you remove the setter operation of a changeable property |
Property becomes Read-only |
If you remove the getter operation of a changeable property |
Property becomes Write-only |
On the other hand, if you modify the property changeability, operations will reflect this change, for example, if you turn a changeable property into a read-only property, the setter operation is automatically removed.
In the following example, class Button contains a property Caption. The Getter operation has been removed which causes the WriteOnly keyword to appear in the property declaration line:
Public Class Button Private captionValue As String Public WriteOnly Property Caption() As String Set (ByVal Value As String) captionValue = value Repaint() End Set End Property End Class
Must override: Set the Must override extended attribute of the property to True to express that the property in a base class must be overridden in a derived class before it can be used
Overridable: Set the Overridable extended attribute of the property to True to express that the property can be overridden in a derived class
Overrides: Set the Overrides extended attribute of the property to True to express that a property overrides a member inherited from a base class
Parameters: Type a value in the value box of the Property parameters extended attribute to specify which value of the property attribute is to be used as parameter. In the following example, class Person contains property attribute ChildAge. The parameter used to sort the property is ChildName:
Public Class Person Private _ChildAge As Integer Private Property ChildAge(ChildName as String) As Integer Get return _ChildAge End Get Set (ByVal Value ChildAge As Integer) If (_ChildAge <> newChildAge) _ChildAge = newChildAge End If End Set End Property End Class