Java观察者与策略的结合?

标签 java design-patterns

我使用了 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/

相关文章:

java - 如何在 Java 中扩展工厂方法模式中的类

c++ - 我们如何访问如下输出? (数字星号)

java - 相对文件路径在 Eclipse 中如何工作?

Java LinkedHashMap 获取第一个或最后一个条目

Java重构代码重复

java - 如何定义一个好的存储库接口(interface)

c# - 缓存数据库查询的最佳方法是什么

java - 当前的 msgraph-sdk-java 是否准备好用于生产级应用程序

java - 使用 CellList 禁用选择

python - 如何使用 Python 创建单例?