Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Public Variables or Object Properties
Message
 
To
24/05/2001 12:46:09
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00510878
Message ID:
00513709
Views:
20
Kev,

Here's why.

The wider the scoping of a variable the more likely there will be a conflict with something. Therefore, no variable should ever be scoped wider than is necessary for it to function appropriately.

A private variable declared in the top level program is visible to every program and emthod called from that one (global to the application). It is also automatically cleaned up when the app ends.

A public is visible to the entire application but it is NOT cleaned up when the app ends. It hangs around and perhaps causes problems with other apps. Even if you release it at your apps end you may still have problems. Imagine the following;

app one: main object name is oApp and it is PUBLIC, this app is a contact manager

app two: main object name is oApp and it is public. This is an accounting app.

App one is running.

App two is started.

App one tries to call a method of main object named DoSetup to set up for a new salesperson. However since app two has started the variable named oApp is now the accouting main object and it has a method named DoSetup that sets up data files for a new company. Think about it ...

Conclusion PROPERTIES of objects are the best because they belong to the objects, LOCALS are the next best because they belong to a particular procedure or method, PRIVATES are the second worst because they are visible to called routines, and PUBLICS are the absolute wiorst because they hang around even if the creating code has finished.



>Craig
>
>>An excellent practice. You should also declare you application object as PRIVATE in your MAIN.PRG.
>
>Why should I use private? at the moment I have it as a Public.
>
>Kev
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform