David Geary (JavaWorld.com, 04/26/02) points out that the Strategy pattern embodies several of the OOP principles put forth by Gamma, Helm, Johnson and Vlissides. One of those principles is
Encapsulate the concept that varies
Eric and Elisabeth Freeman (Head First Design Patterns, O'Reilly 2004) make the same point in discussing the Strategy pattern, and we're not ones to break tradition and miss an important connection between a design pattern and an OOP concept.
In Chapter 10, you saw that with the State design pattern, the states varied in the video player, and so the State object encapsulated the state-dependent behavior, such as playing and stopping the video. With the Strategy pattern, the Strategy object encapsulates algorithms. What both these design patterns have in common is that the elements that change are encapsulated. (As a hint of what is encapsulated, look at the name of the class. In both the State and Strategy classes, the encapsulating object is the name of the class—check the class diagrams.)
More important is why GoF suggests encapsulating those concepts that vary. Essentially, if you encapsulate those parts that vary, then, when you change the application, you'll have fewer surprises. Encapsulated concepts allow the objects in object-oriented programming to act like objects. Rather than being sticky-glued to and dependent on other elements in a single program, encapsulated objects can act in ...