Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the strategy pattern called the strategy pattern?

Of course you can regard it as a kind of strategy, but that applies to almost all the design patterns. So : why?

like image 592
Peter Avatar asked Nov 16 '09 16:11

Peter


2 Answers

Because some of the components implement strategies, "ways to achieve something".

The point of the strategy pattern is to let you choose a way of doing something, a "strategy", at runtime.

The name doesn't refer to the pattern as a whole, it refers to the objects within the pattern that perform actions.

like image 85
RichieHindle Avatar answered Oct 01 '22 07:10

RichieHindle


The idea behind the strategy pattern is that "algorithms can be selected at runtime." (Wikipedia, Strategy Pattern) The pattern, in essence, is selecting the right strategy (or behavior) for solving a particular problem at runtime. Hence, it's name.

like image 45
JasCav Avatar answered Oct 01 '22 07:10

JasCav