我必须找到以下问题的解决方案:
我有很多模型对象。一些模型对象依赖于其他模型对象。当引用的模型对象发生变化时,依赖项必须失效。我需要存储当前无效对象的列表,这样我就可以将其显示给用户,并让他有机会重新生成对象(如果他想这样做)。问题是我将如何组织和存储对象具有的依赖项,以及当某些对象更改/失效时如何提供和接收信息。
有人可以提供想法,或者这个问题可能存在一些类似的模式
最佳答案
听起来您需要 Observer pattern :
The observer pattern (aka. Dependents, publish/subscribe) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
关于oop - 用于管理对象依赖关系的设计模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9614873/