我使用了 MVC 模式和观察者模式的组合,其中我的 View 是观察者,我的模型是具有状态的主体。
可以使用策略模式来更改我的主题/模型中的状态吗?因为我需要实现多种行为?
最佳答案
是的。您可以实现设计模式的组合来解决您的问题。我想强调以下有关设计模式的要点
- Design patterns are solutions for recurring common problems. They are guidelines to solve a particular problem.
- You can create your own design pattern for your problem. Solving your problem is important than fitting your solution into one of existing design patterns.
- Sometimes design patterns will limit our thinking process into available design patterns,which is not good. You should not be constrained about existing patterns
- Design patterns are facilitators but they are not obligatory
关于Java观察者与策略的结合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31946559/