Skip to Content
Head First Design Patterns, 2nd Edition
book

Head First Design Patterns, 2nd Edition

by Eric Freeman, Elisabeth Robson
December 2020
Beginner
672 pages
15h 24m
English
O'Reilly Media, Inc.
Content preview from Head First Design Patterns, 2nd Edition

Chapter 8. Encapsulating Algorithms: The Template Method Pattern

Images

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. Let’s get started...

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:

Images

Whipping up some coffee and tea classes (in Java)

Images

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

Here’s the coffee:

Images

And now the Tea...

Images
Images
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Designing Data-Intensive Applications, 2nd Edition

Designing Data-Intensive Applications, 2nd Edition

Martin Kleppmann, Chris Riccomini
Design Patterns: Elements of Reusable Object-Oriented Software

Design Patterns: Elements of Reusable Object-Oriented Software

Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides

Publisher Resources

ISBN: 9781492077992Errata PageSupplemental Content