Reputation: 48486
I'm working on a redesign for part of an existing application and I'm having a bit of an issue with the toughest programming problem of all: naming things correctly :)
I have a class (A
) which can create instances of B
. Each A
has an active B
object.
To activate the object, it calls a method Initialize
on B
, passing a reference to itself. B
will check the state of A
, subscribe to changes in A
, etc.
At some point, A
can decide it no longer needs B
, at which point B
goes into a pool of objects that can be reused. A different instance of A
can decide to pick up the existing B
object instead of creating one.
When this happens, the Initialize
method is called again on the existing object B
.
Now, I have the feeling that this could be confusing because people will probably expect initialization to happen only once. Is there a better generic term I could use in this situation? I would also like to introduce a complement of the Initialize
method, that tells B
it can stop paying attention to A
.
Upvotes: 1
Views: 43
Reputation: 10855
In similar situations I have used Attach() and Dettach() to represent a transitory connection between objects.
bInstance.Attach(this)
and later when putting it back in the pool
bInstance.Dettach()
Upvotes: 0
Reputation: 1195
I think you already hit on the term in your description:
To activate the object, it calls a method Initialize on B, passing a reference to itself.
Activate and Deactivate would be appropriate method names.
Upvotes: 2