Polymorphism vs Strategy pattern

后端 未结 10 921
陌清茗
陌清茗 2021-01-30 10:12

What is the difference between the Strategy pattern and Polymorphism in Java?

I\'m confused that whatever is achieved via Strategy Pattern is

10条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 10:50

    If you are establishing an analogy where:

    • in one case you have several overridable methods;
    • in the other case you have a Strategy interface with several implementations,

    then the difference is the degree of coupling, which is very strong in the first case, whereas in the second case any foreign code can participate in your class's logic by contributing its Strategy implementation.

提交回复
热议问题