Tuesday, September 19, 2006

.NET Class

@ Fields are variables delcared in the class so that they are available to all code within the class, and are available to each individual object.

@ Fields are also called instance variables or member variables.

@ Fields are used by objects to store data.

@ Typically, fields are Private in scope, available only to the code in the class itself.
Never declare a field as Public, beacuse such a choice directly breaks the concept of encapsulation, since code outside the object can directly change data values without following any rules set in the object.

@ If you want to make the value of a field available to code outside of the object, you should use a property:
Public Class OneClass
Private FieldName As String
Private FieldAge As Integer
Public ReadOnly Property Name() As String
Get
Return FieldName
End Get
End Property
End Class

^ 要实现Java中的Field + Getter & Setter Method的关系,在VB中恐怕就要用Field + Property Method的方法了。

@ You shouldn't confuse fields with properties. In Visual Basic, a Property is a type of method that is geared to retrieving and setting values, while a field is a variable within the class that may hold the value exposed by a Property.