When to choose a strategy over polymorphism when reorganizing a switch statement

Can you give me a specific reason when you need to choose stratergy over polymorphsim and vice versa.

Thank you so much!

+5
source share
2 answers

One important criterion is whether polymorphism will create a relationship that this strategy could avoid. For example, if you implement the “save ()” method for a class tree, which means using low-level I / O functions, then if you use polymorphism, the class tree will be bound to the I / O system, whereas it wasn’t “t until. However, if you use a strategy template, the strategy objects will serve as a “buffer” and save the class tree depending on the I / O.

+4
source

You start your application with a null value.

The next step is raw code with polymorphism.

In basic cases, he can remain so - this is not a problem.

, , , , - . - , , .


:

, . , .


:

. :

. , , , line . , .

. . , .

. . , , . , , .


:
  • . . .

  • . Inheritance . Context . Context.It Context's, , . . , - , . , , .

  • . . , . .

+1

All Articles