Cover by Eric Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 8. The Template Method Pattern: Encapsulating Algorithms

image with no caption

We’re on an encapsulation roll; we’ve encapsulated object creation, method invocation, complex interfaces, ducks, pizzas... what could be next? We’re going to get down to encapsulating pieces of algorithms so that subclasses can hook themselves right into a computation anytime they want. We’re even going to learn about a design principle inspired by Hollywood.

It’s time for some more caffeine

Some people can’t live without their coffee; some people can’t live without their tea. The common ingredient? Caffeine of course!

But there’s more; tea and coffee are made in very similar ways. Let’s check it out:

image with no caption

Whipping up some coffee and tea classes (in Java)

Let’s play “coding barista” and write some code for creating coffee and tea.

image with no caption

Here’s the coffee:

image with no caption

and now the Tea...

image with no caption
image with no caption

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required