Using Property Procedures

Exposing variables by declaring them Public can be a dangerous practice. As more and more programs (and programmers!) use a given class, the likelihood increases that one of them will misinterpret or incorrectly modify a Public variable and cause your class to fail.

The best way to avoid this is to make variable declarations Private. If code outside your class can’t access the variable at all, it can’t access it improperly! This solution, of course, presents a second problem: with no access to Public variables, how can the calling program supply and retrieve data values? Property procedures provide the answer. To visualize how property procedure works, first consider the following code:

Public Class OrderData Private intOrdQty ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.