Polymorphism vs Strategy pattern

后端 未结 10 923
陌清茗
陌清茗 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条回答
  •  离开以前
    2021-01-30 11:03

    Here is the concise response:

    1. Polymorphism is one of the fundamental characteristics of object-oriented programming.
    2. Strategy pattern is a language-independent pattern that can be implemented by all programming languages paradigms, such as imperative, functional, and object-oriented.

    Therefore, if you are going to implement Strategy pattern by using Java, that is OOP, then you just need to use polymorphism.

    In other words, Strategy pattern is one of many forms of polymorphism.

提交回复
热议问题