Head First Design Patterns, 2nd Edition
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
What will you learn from this book?
You know you don't want to reinvent the wheel, so you look to Design Patterns: the lessons learned by those who've faced the same software design problems. With Design Patterns, you get to take advantage of the best practices and experience of others so you can spend your time on something more challenging. Something more fun. This book shows you the patterns that matter, when to use them and why, how to apply them to your own designs, and the object-oriented design principles on which they're based. Join hundreds of thousands of developers who've improved their object-oriented design skills through Head First Design Patterns.
What's so special about this book?
If you've read a Head First book, you know what to expect: a visually rich format designed for the way your brain works. With Head First Design Patterns, 2E you'll learn design principles and patterns in a way that won't put you to sleep, so you can get out there to solve software design problems and speak the language of patterns with others on your team.
Show and hide more
Publisher resources
Table of contents Product information
Table of contents
- Authors of Head First Design Patterns
- Creators of the Head First Series
- Table of Contents (the real thing)
- Intro: How to use this Book
- Who is this book for?
- Who should probably back away from this book?
- We use simple UML-like diagrams.
- We don’t cover every single Design Pattern ever created.
- The activities are NOT optional.
- We use the word “composition” in the general OO sense, which is more flexible than the strict UML use of “composition.”
- The redundancy is intentional and important.
- The code examples are as lean as possible.
- The Brain Power exercises don’t have answers.
- From the first edition
- From the second edition
- Very Special Thanks
- It started with a simple SimUDuck app
- But now we need the ducks to FLY
- But something went horribly wrong.
- Joe thinks about inheritance.
- How about an interface?
- What would you do if you were Joe?
- The one constant in software development
- Zeroing in on the problem.
- Separating what changes from what stays the same
- Designing the Duck Behaviors
- Implementing the Duck Behaviors
- there are no Dumb Questions
- Integrating the Duck Behaviors
- More integration.
- Testing the Duck code
- Setting behavior dynamically
- The Big Picture on encapsulated behaviors
- HAS-A can be better than IS-A
- Speaking of Design Patterns.
- Design Puzzle
- Overheard at the local diner.
- Overheard in the next cubicle.
- The power of a shared pattern vocabulary
- How do I use Design Patterns?
- there are no Dumb Questions
- Tools for your Design Toolbox
- Design Patterns Crossword
- Design Puzzle Solution
- Design Patterns Crossword Solution
- The Weather Monitoring application overview
- Unpacking the WeatherData class
- Our Goal
- Stretch Goal
- Taking a first, misguided implementation of the Weather Station
- What’s wrong with our implementation anyway?
- Meet the Observer Pattern
- Publishers + Subscribers = Observer Pattern
- A day in the life of the Observer Pattern
- Five-minute drama: a subject for observation
- Two weeks later.
- The Observer Pattern defined
- The Observer Pattern: the Class Diagram
- there are no Dumb Questions
- The Power of Loose Coupling
- Cubicle conversation
- Designing the Weather Station
- Implementing the Weather Station
- Implementing the Subject interface in WeatherData
- Now, let’s build those display elements
- there are no Dumb Questions
- Power up the Weather Station
- Looking for the Observer Pattern in the Wild
- The Swing library
- A little life-changing application
- For the Subject to send notifications.
- For an Observer to receive notifications.
- Welcome to Starbuzz Coffee
- The Open-Closed Principle
- there are no Dumb Questions
- Meet the Decorator Pattern
- Constructing a drink order with Decorators
- Okay, here’s what we know about Decorators, so far.
- Identifying the aspects that vary
- But the pressure is on to add more pizza types
- Encapsulating object creation
- Building a simple pizza factory
- there are no Dumb Questions
- Reworking the PizzaStore class
- The Simple Factory defined
- Franchising the pizza store
- We’ve seen one approach.
- But you’d like a little more quality control.
- Let’s see how it works: ordering pizzas with the pizza factory method
- So how do they order?
- Let’s check out how these pizzas are really made to order.
- Our Pizza Store isn’t going to be very popular without some pizzas, so let’s implement them
- Now we just need some concrete subclasses. how about defining New York and Chicago-style cheese pizzas?
- The Creator classes
- The Product classes
- Ensuring consistency in your ingredients
- Ethan and Joel can’t get enough Objectville Pizza! What they don’t know is that now their orders are making use of the new ingredient factories. So now when they order.
- From here things change, because we are using an ingredient factory
- The Little Singleton
- A small Socratic exercise in the style of The Little Lisper
- 1. Do nothing if the performance of getInstance() isn’t critical to your application.
- 2. Move to an eagerly created instance rather than a lazily created one.
- 3. Use “double-checked locking” to reduce the use of synchronization in getInstance().
- Home Automation or Bust, Inc.
- Free hardware! Let’s check out the Remote Control.
- Taking a look at the vendor classes
- Cubicle Conversation
- Meanwhile, back at the Diner. or, A brief introduction to the Command Pattern
- Let’s study the interaction in a little more detail.
- The Objectville Diner roles and responsibilities
- From the Diner to the Command Pattern
- Our first command object
- Using the command object
- Creating a simple test to use the Remote Control
- The Command Pattern defined
- The Command Pattern defined: the class diagram
- Assigning Commands to slots
- Implementing the Remote Control
- Implementing the Commands
- Putting the Remote Control through its paces
- Now, let’s check out the execution of our remote control test.
- Adapters all around us
- Object-oriented adapters
- If it walks like a duck and quacks like a duck, then it must might be a duck turkey wrapped with a duck adapter.
- Test drive the adapter
- The Adapter Pattern explained
- Here’s how the Client uses the Adapter
- Enumerators
- Iterators
- Using Enumerators with code that expects Iterators
- Designing the Adapter
- Dealing with the remove() method
- Writing the EnumerationIterator adapter
- Keeping your method calls in bounds.
- It’s time for some more caffeine
- Whipping up some coffee and tea classes (in Java)
- And now the Tea.
- Let’s abstract that Coffee and Tea
- Taking the design further.
- Abstracting prepareRecipe()
- What have we done?
- Meet the Template Method
- Let’s make some tea.
- What did the Template Method get us?
- Template Method Pattern defined
- Hooked on Template Method.
- Using the hook
- Let’s run the Test Drive
- And let’s give it a run.
- Let the sorting commence!
- Breaking News: Objectville Diner and Objectville Pancake House Merge
- Check out the Menu Items
- Lou and Mel’s Menu implementations
- What’s the problem with having two different menu representations?
- The Java-Enabled Waitress Specification
- Here’s the test run.
- Here’s the test run; check out the new dinner menu from the Café!
- Fixing the print() method
- Java Breakers
- Cubicle Conversation
- State machines 101
- Writing the code
- In-house testing
- You knew it was coming. a change request!
- Design Puzzle
- The messy STATE of things.
- The new design
- Defining the State interfaces and classes
- Implementing our State classes
- Reworking the Gumball Machine
- Now, let’s look at the complete GumballMachine class.
- Implementing more states
- Let’s take a look at what we’ve done so far.
- The State Pattern defined
- there are no Dumb Questions
- We still need to finish the Gumball 1 in 10 game
- Finishing the game
- Demo for the CEO of Mighty Gumball, Inc.
- there are no Dumb Questions
- Sanity check.
- We almost forgot!
- Tools for your Design Toolbox
- Design Puzzle Solution
- Coding the Monitor
- Testing the Monitor
- The role of the ‘remote proxy’
- Walking through the design
- And now let’s put the monitor in the hands of the CEO. Hopefully, this time he’ll love it:
- Remote Proxy
- Virtual Proxy
- How ImageProxy is going to work:
- Things to try.
- Working together
- Duck reunion
- there are no Dumb Questions
- What did we do?
- A duck’s-eye view: the class diagram
- The King of Compound Patterns
- If Elvis were a compound pattern, his name would be Model-View-Controller, and he’d be singing a little song like this.
- Meet the Java DJ View
- The controller is in the middle.
- Let’s not forget about the model underneath it all.
- Let’s check out the BeatModelInterface before looking at the implementation:
- And here’s the implementation of the controller:
- And now for a test run.
- Things to try
- And that’s it! Now it’s time for some test code.
- Things to try
- The Beat Model
- The View
- The Controller
- The Heart Model
- The Heart Adapter
- The Controller
- Design Pattern defined
- Looking more closely at the Design Pattern definition
- there are no Dumb Questions
- So you wanna be a Design Patterns writer
- Organizing Design Patterns
- Pattern Categories
- Thinking in Patterns
- Keep it simple (KISS)
- Design Patterns aren’t a magic bullet; in fact, they’re not even a bullet!
- You know you need a pattern when.
- Refactoring time is Patterns time!
- Take out what you don’t really need. Don’t be afraid to remove a Design Pattern from your design.
- If you don’t need it now, don’t do it now.
- The definitive Design Patterns text
- The definitive Patterns texts
- Other Design Patterns resources
- Bridge
- Your dilemma
- You need a flexible design
- A scenario
- Your task
- A scenario
- Your big client’s dilemma
- A scenario
- Now what?
- A scenario
- HouseOfTheFuture’s dilemma
- A scenario
- A scenario
- A scenario
Show and hide more
Product information
- Title: Head First Design Patterns, 2nd Edition
- Author(s): Eric Freeman, Elisabeth Robson
- Release date: December 2020
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492078005