Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Methods available according to state

Status
Not open for further replies.

JaseUK

IS-IT--Management
Jun 19, 2001
21
GB
Dear all,

Can someone tell me if it is possible to alter the visibility of the methods in an object (public/private) according to the state of the object? Or do I just have to put code to handle this in each method?

eg: When the connect method is called in my object I would like to add extra functionality, but remove it once the disconnect method is called. This would make sense to me, but maybe not to anyone else. The only problem I could see is how an editor would understand how the rules apply at design time.

With thanks,
Jason.
 
Classes are design time, Objects are run time. The class simply describes what the object looks like and how it reacts. A member's visibility defines who can know about the member when the object is made. Design can only know that the object has certain states, it is oblivious to what state the object is in. To it, the object doesn't really exist. Fireing a method or setting a property doesn't mean the object shifts into a new state.

Remember, your ability to use a member does not define its visibility.

Take this sample code:
[tt]
Obj = New ClassObj
Obj.Connect
Obj.AllowedWhenConnected
[/tt]
Is the editor/compiler supposed to assume that AllowedWhenConnected is valid just because a connect statement is only one line before it.

WHAT IF
the connection fails, design cannot know this, you must code for it.
the connection gets changed by any one of a million six different things

The bottom line is that you do not want what you asked for. Even if it helps foster proper practices with your object, too many run time environment factors make it unreasonable.

Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top