Chapter 9. Template Method Pattern

If you write a post and put it on a blog, that’s a historical document. If you change your template, then that entry looks completely different. It’s the same words, but not the same meaning. This all depends on what historical questions that people will be asking and we can’t know what they will want.

Josh Greenberg

Well, I did all the pre-production and I did full demos of all the songs and then I took it into the studio and played it for all the guys and then we kind of took that as the template and did the album live very quickly.

David Sanborn

What is the Template Method Pattern?

You’re going to like this pattern. Essentially the template method is an algorithm made up of a sequence of operations that accomplishes some goal. Imagine a general set of steps for getting something done such as going to work. If you take a car, boat, or airplane to work, you’re going to be doing certain things that are similar and others that are different. You’ll be transporting yourself in a vehicle, guiding it to a particular location, and you always grab a cup of coffee to take with you. So if you make a general template that covers going by car, boat, or airplane, your outline (algorithm) would look something like the following:

  1. Prepare transportation.

  2. Navigate vehicle.

  3. Drink your cup of coffee.

Preparing a car for transportation usually involves little more than making sure it’s got enough gas and the tires aren’t flat. With a boat, you might want to check to ...

Get ActionScript 3.0 Design Patterns 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.