Property

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
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