Prev | Current Page 142 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

The typical pattern is to provide access to a private field in a class
through a public property.
Properties significantly enhance your flexibility as a class designer. For example, if a property
represents the amount of table rows in a database table object, the table object can defer the
computation of the value until the point where it is queried through a property. It knows when
to compute the value because the client will call an accessor when it accesses the property.
Accessors
Accessors allow you to control access to the state of a class. Get accessors allow for read access,
while Set accessors allow for write access to your properties. Accessors can provide read-write,
read-only, or write-only access to your properties. Beginning with Visual Basic 2005 (VB 2005),
Get and Set accessors can have different accessibility levels, provided that the Set accessor is
more restrictive.
Get blocks are called when the client of the object reads the property. This accessor must
return a value or an object reference that matches the type of the property declaration. It can
also return an object that is implicitly convertible to the type of the property declaration. For
example, if the property type is a Long and the getter returns an Integer, the Integer will be
implicitly converted to a Long without losing precision.


Pages:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
katalog stron śmieszne dowcipy basen z piłeczkami dieta light życzenia ślubne