Description
Some classes require a member be called before any other usage is allowed, or before an item can be disposed, or if not called - the class isn't being used properly. Sometimes the method can be called internally (by the class itself), and at other times, the consumer of the class needs to invoke the member(s).
@retailcoder suggested a @MustExecute
annotation at the procedure level, but that doesn't seem to allow for the variety of times at which a procedure must be called, and by which code.
Timing
-
Must execute after initialization, but before any other member is called
In the absence of a (suitable) factory method, there may be a requirement that one or more properties be assigned, or methods called, before the class is fully useable. -
Must execute at least n times after initialization, and before destruction
For example, a custom collection class must have at least one call to theAdd
method, or the collection is nothing more than an empty collection. I suppose you could also argue that at least one call toItem
orRemove
is necessary too. -
Must execute after all other member calls, and before destruction
For example, code that consumes achild
object must finally invokechild.Dispose
before the object is destroyed. Another example might beClass_Terminate
must callCleanupDbConnection
.
Source of invocation
-
Must be invoked from inside the class
Might be something as simple asForm_Load
must invokeInitializeControls
andInitializeDbConnection
-
Must be invoked by consumer of the class
For example, code that consumes achild
object must invokechild.Dispose