views:

150

answers:

3

With regards to design patterns such as GoF, is there a pattern to decribe when one object needs to observe another object that is not even in existance yet?

i.e.

$crystalBall = new crystalBall();
$futureDependent = new FutureDependent();
$futureDependent->attach($crystalBall);

...

then much later
....

$importantObject = new ImportantObject()
$crystalBall->sendToFutureDependent($importantObject);

......
then later again


$strawberriesAndCreamMmmmmLovely = $futureDependent->doStuffWithImportantObject();

Its kind of like an observer in reverse. But different in the sense that on observer gets notified of events.

were as this one just wants a reference to it when its created.

Any ideas?


Update - after commenting on Chacha102's answer i realise....Crystal Ball is a Registry...it helped by having to say the words... "difficult to get hold of"

+1  A: 

I don't get why you wouldn't just have the importantObject attach directly to the futureDependant.

Chacha102
cos futureDependent is really difficult to get hold of by the time importantObject is created.but yes...thanks...i'm tired and after a sleep i might just realise that that's the perfect simplest solution.
JW
This should be a comment.
The Pixel Developer