This ideas originate from the MSDN webcast series on VB.NET OOP Programming by Dr. Joe Hummel.
Class Design Rule 1: Use Constructors to guarantee initialization. Constructors are special methods named New.
Overload the New methods by forward calling another constructure with more elaborate signature, and supply default values for certain parameters.
Example:
Public Sub New()
' Call overloaded method with default values for unknown parameters.
Me.New(0, "")
End Sub
Public Sub New(ByVal Amount As Integer, ByVal Name As String)
' Initialize fields...
End Sub
Class Design Rule 2: Implement the ToString() method to return a meaningful string representation of the object.
Example:
Public Overrides Function ToString() As String
Return Me.Name
End Function
Class Design Rule 3: Apply Data Hiding whenever possible by using Fields. Proved method-level access to the fields as to control data validation, enable persistance, security, and use execption-handling.
Class Design Rule 4: Supply a method for cloning the object, a method that returns a complete copy. .NET has a built in method for copying fields called MemberwiseClone().
Example:
Public Function Clone() As Object
Return Me.MemberwiseClone()
End Function