Head First Design Patterns, 2nd Edition

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

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