Chapter 2. Putting Plans into Action with the Strategy Pattern

<feature> <title>In This Chapter</title> <objective>

Extending object-oriented programming

</objective>
<objective>

Getting to know abstraction, encapsulation, polymorphism, and inheritance

</objective>
<objective>

Switching from “is-a” to “has-a”

</objective>
<objective>

Handling tasks using algorithms

</objective>
<objective>

Bringing the Strategy pattern to the rescue

</objective>
</feature>

As you, the design pattern expert, walk into the boardroom of MegaGigaCo, the CEO and members of the board are celebrating their new contract to design a set of cars in the sedate way you’d expect — by high-fiving each other and whooping around the room.

“This contract is going to mean a huge amount of income for us,” says the CEO, sloshing a little champagne on the boardroom table in his excitement. “All we’ve got to do is make sure we get the design process right.” He turns on the overhead projector, and as several large charts appear on the wall, the CEO says, “Now here’s my idea . . .”

“Wrong,” you say.

The CEO looks startled, and says, “But if we . . .”

“Nope,” you say, shaking your head.

“What . . .”

“Sorry,” you tell the CEO and the board, “it’s clear you’re risking your entire contract by doing things the wrong way. I can see a dozen problems just looking at that chart.”

The board murmurs with concern and the CEO asks, “And you are?”

“I’m the design pattern pro who’s going to solve all your design problems,” you say. “For a whopping fee, ...

Get Design Patterns For Dummies® 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.