[dba-VB] Owner scope

jwcolby jwcolby at colbyconsulting.com
Wed Nov 2 07:41:21 CDT 2011


A couple of questions:

We use the term parent for inheritance.  What is the term for the "owner" of a variable or class. 
IOW I use a RunState class.  A process class can have class level variables which are initialized to 
instances of this class.  Thus (in my terminology) the class "owns" these RunState class instances. 
  What I am windering is if there is a OO term for this "owner" concept.

Next question.  The run state class has methods and properties.  Some of the methods, specifically 
the Start method should be visible from the object trying to "start" the process.  Other methods 
should only be called from the "owner" of the RunState class.  What is the syntax for scope to make 
some properties and methods only visible from the owner side?

I am trying to build a state machine where the RunState class starts at state Stopped.

clsRunState has 4 states.
1) Stopped
2) Starting
3) Started
4) Stopped

State changes can only be done by clsRunState, IOW it is not possible to directly set the RunState 
from outside of clsRunState.  This allows clsRunState to enforce the state machine rules / transitions.

clsRunState has 5 methods
1) mStart - called by the external process starting this process
2) mInitialized - Called by the owner to signal that Initialization completed
3) mInitFailed - Called by the owner to indicate that initialization failed, passing in error info
4) mStop - Called by the external process or the owner to trigger cleanup and stopping
5) mTerminated - called by the owner to signal that termination is complete

clsRunState has 2 events
1) evInitialize - Raised by mStart() and sunk by the owner to trigger initialization code.
2) evTerminate - Raised by mStop() and sunk by the owner to trigger cleanup and shutdown.

1) The process is started when an external process calls the clsRunState.mStart() method (from 
outside of the owner).  If the state was Stopped when entering mStart, then clsRunState sets the 
state to Starting and raises an evInitialize event which is sunk in the "owner" (whatever we are 
calling that).  If the state was not Stopped when clsRunState.mStart() is called then the method 
just returns, doing nothing.

The owner sinks the evInitialize and performs initialization.  If the initialization works then the 
owner calls the clsRunState.mInitialized() method which sets the RunState to Started.

If initialization fails then the the owner calls clsRunState.mInitFailed() passing in a fail text 
message which is stored in a property for the external process to read.  clsRunState.mInitFailed() 
then sets the RunState to Stopped.

The external process or the owner can call clsRunState.mStop().  clsRunState.mStop() sets the 
RunState to Stopping and raises the evTerminate event which is sunk by the owner and is used to 
trigger cleanup of the process controlled by the RunState class.

When the owner finishes all termination processes the owner calls clsRunState.mTerminated() which 
sets the RunState to Stopped.

I need the scope syntax to prevent the external process from calling methods that only the owner is 
supposed to call.

-- 
John W. Colby
Colby Consulting

Reality is what refuses to go away
when you do not believe in it



More information about the dba-VB mailing list