In my application, I'm creating an object that may be referenced in multiple locations (added into multiple Collections). Change it once and it is changed for all the different references (correct functionality - everyone sees the change).
What I need is the ability to delete the object (remove all the references in the assorted collections, etc..). Is there some design pattern or methodology that can help me accomplish this?
Thanks for any help!
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
Don't think so.
You might give everyone a reference to a shell that has a private instance of the real thing. Then you'd only have to null out the reference in the shell to unlink all references to the real thing. All the other collections could reference the shell but they'd find it in an invalid state of some kind.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jeremy French
Greenhorn
Joined: May 11, 2005
Posts: 13
posted
0
You could create a listener-type structure, assuming you control all the Collection classes - i.e. they are subclasses, not the native ones. Then adding your deleteable object to the collection would at the same time register the Collection object with the deleteable object. Then when you need to delete the object, loop through your registered listeners and request they nullify their reference to you.
At least I think that would work...
There are 10 kinds of people in the world. Those that read binary and those that don't.
Ernest Friedman-Hill
author and iconoclast
Marshal
A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Fake names and "handles" aren't acceptable here. You can change your display name here. Thanks!
The Observer pattern defines an one-to-many dependency between a subject object and any number of observer objects so that when the subject object changes state, all its observer objects are notified and updated automatically. The Observer pattern is also known as Dependents and Publish-Subscribe