关于GoF等设计模式,当一个物体需要观察另一个甚至不存在的物体时,是否有一种模式可以描述?
即
$crystalBall = new crystalBall();
$futureDependent = new FutureDependent();
$futureDependent->attach($crystalBall);
...
then much later
....
$importantObject = new ImportantObject()
$crystalBall->sendToFutureDependent($importantObject);
......
then later again
$strawberriesAndCreamMmmmmLovely = $futureDependent->doStuffWithImportantObject();
它有点像反向的观察者。 但在观察者得到事件通知的意义上是不同的。
因为这个人只是想在创建它时引用它。
有什么想法吗?
更新 - 在评论Chacha102的答案后,我意识到...... Crystal Ball是一个注册表......它不得不说出来的话......“很难掌握”
答案 0 :(得分:0)
我偶然发现了'未来'的概念
请参阅: * http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Future.html
Interface Future<V>
Type Parameters:
V - The result type returned by this Future's get method
...
正如所讨论/引用的那样:
不确定它是否是一种模式。
答案 1 :(得分:0)
我能想到的最接近的是Reflection,你可以“分析”一个类,也可以根据你使用clone发现的内容创建一个新类。
http://php.net/manual/en/book.reflection.php
否则会出现“实验性”对象聚合,现在用处不大。