5.1. Strategy

The Strategy pattern is an example of delegation, the general object-oriented idiom that was mentioned in the last chapter. Before starting, we should mention that in discussing implementations of patterns such as the Strategy pattern it will be helpful to use obvious, illustrative class names like Context and Strategy, as in Figure 5.2. But of course when you use the software patterns in your own code you can call your classes anything you like.

Figure 5.2. The Strategy pattern

The problem addressed by the Strategy pattern is when we have a range of objects, all members of the same class called, let’s say, Context, and we want ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.