0%

Book Description

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 that 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 the patterns are based.

Most importantly, you want to learn design patterns in a way that won’t put you to sleep. If you’ve read a Head First book, you know what to expect—a visually rich format designed for the way your brain works. Newly updated and expanded, Head First Design Patterns, 2E, will load patterns into your brain in a way that sticks. In a way that makes you better at solving software design problems and better at speaking the language of patterns with others on your team.

Join the hundreds of thousands of developers who have already improved their object-oriented design skills through Head First Design Patterns.

Table of Contents

  1. 1. Intro to Design Patterns: Welcome to Design Patterns
    1. It started with a simple SimUDuck app
    2. But now we need the ducks to FLY
    3. But something went horribly wrong...
      1. What happened?
    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. Integrating the Duck Behavior
    13. More integration...
    14. Testing the Duck code
    15. Setting behavior dynamically
    16. The Big Picture on encapsulated behaviors
    17. HAS-A can be better than IS-A
    18. Speaking of Design Patterns...
    19. Design Puzzle
    20. Overheard at the local diner...
    21. Overheard in the next cubicle...
    22. The power of a shared pattern vocabulary
    23. How do I use Design Patterns?
    24. Tools for your Design Toolbox
    25. Design Patterns Crossword
    26. Design Puzzle Solution
    27. Design Patterns Crossword Solution
  2. 2. The Observer Pattern: Keeping your Objects in the Know
    1. The Weather Monitoring application overview
    2. Unpacking the WeatherData class
    3. Our Goal
    4. Stretch Goal
    5. Taking a first, misguided SWAG at 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. The Power of Loose Coupling
    15. Cubicle conversation
    16. Designing the Weather Station
    17. Implementing the Weather Station
    18. Implementing the Subject interface in WeatherData
    19. Now, let’s build those display elements
    20. Power up the Weather Station
    21. Looking for the Observer Pattern in the Wild
      1. The Swing library
      2. A little life-changing application
    22. Coding the life-changing application
    23. Meanwhile back at Weather-O-Rama
      1. For the Subject to send notifications...
      2. For an Observer to receive notifications...
    24. Code Magnets
    25. Test Drive the new code
    26. Tools for your Design Toolbox
    27. Design Principle Challenge
    28. Design Patterns Crossword
      1. Design Principle Challenge Solution
    29. Code Magnets Solution
    30. Design Patterns Crossword Solution
  3. 3. The Decorator Pattern: Decorating Objects
    1. Welcome to Starbuzz Coffee
    2. The Open-Closed Principle
    3. Meet the Decorator Pattern
    4. Constructing a drink order with Decorators
      1. Okay, here’s what we know about Decorators, so far...
    5. The Decorator Pattern defined
    6. Decorating our Beverages
    7. Cubicle Conversation
    8. New barista training
    9. Writing the Starbuzz code
    10. Coding beverages
    11. Coding condiments
    12. Serving some coffees
    13. Real World Decorators: Java I/O
    14. Decorating the java.io classes
    15. Writing your own Java I/O Decorator
    16. Test out your new Java I/O Decorator
    17. Tools for your Design Toolbox
  4. 4. The Factory Pattern: Baking with OO Goodness
    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. Reworking the PizzaStore class
    6. The Simple Factory defined
    7. Franchising the pizza store
      1. We’ve seen one approach...
      2. But you’d like a little more quality control...
    8. A framework for the pizza store
    9. Allowing the subclasses to decide
    10. Let’s make a PizzaStore
    11. Declaring a factory method
      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...
    12. We’re just missing one thing: Pizzas!
      1. Our PizzaStore 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 st yle cheese pizzas?
    13. You’ve waited long enough. Time for some pizzas!
    14. It’s finally time to meet the Factory Method Pattern
      1. The Creator classes
      2. The Product classes
    15. View Creators and Products in Parallel
    16. Design Puzzle
    17. Factory Method Pattern defined
    18. Looking at object dependencies
    19. The Dependency Inversion Principle
    20. Applying the Principle
    21. Inverting your thinking...
    22. A few guidelines to help you follow the Principle...
    23. Meanwhile, back at the PizzaStore...
      1. Ensuring consistency in your ingredients
    24. Families of ingredients...
    25. Building the ingredient factories
    26. Building the New York ingredient factory
    27. Reworking the pizzas...
    28. Revisiting our pizza stores
    29. What have we done?
    30. More pizza for Ethan and Joel...
      1. From here things change, because we are using an ingredient factory
    31. Abstract Factory Pattern defined
    32. Factory Method and Abstract Factory compared
    33. Tools for your Design Toolbox
    34. Design Patterns Crossword
    35. Design Puzzle Solution
    36. Design Patterns Crossword Solution
  5. 5. The Singleton Pattern: One of a Kind Objects
    1. The Little Singleton
      1. A small Socratic exercise in the st yle of The Little Lisper
    2. Dissecting the classic Singleton Pattern implementation
      1. Patterns Exposed
    3. The Chocolate Factory
    4. Singleton Pattern defined
    5. Hershey, PA, we have a problem...
    6. BE the JVM
    7. Dealing with multithreading
    8. Can we improve multithreading?
      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().
    9. Meanwhile, back at the Chocolate Factory...
    10. Congratulations!
    11. Tools for your Design Toolbox
      1. Design Patterns Crossword
    12. BE the JVM Solution
      1. Design Patterns Crossword Solution
  6. 6. The Command Pattern: Encapsulating Invocation
    1. Free hardware! Let’s check out the Remote Control...
    2. Taking a look at the vendor classes
    3. Cubicle Conversation
    4. Meanwhile, back at the Diner..., or, A brief introduction to the Command Pattern
    5. Let’s study the interaction in a little more detail...
    6. The Objectville Diner roles and responsibilities
    7. From the Diner to the Command Pattern
    8. Our first command object
    9. Using the command object
    10. Creating a simple test to use the Remote Control
    11. The Command Pattern defined
    12. The Command Pattern defined: the class diagram
    13. Assigning Commands to slots
    14. Implementing the Remote Control
    15. Implementing the Commands
    16. Putting the Remote Control through its paces
    17. Now, let’s check out the execution of our remote control test...
    18. Time to write that documentation...
    19. What are we doing?
    20. Time to QA that Undo button!
    21. Using state to implement Undo
    22. Adding Undo to the CeilingFan commands
    23. Get ready to test the ceiling fan
    24. Testing the ceiling fan...
    25. Every remote needs a Party Mode!
    26. Using a macro command
    27. More uses of the Command Pattern: queuing requests
    28. More uses of the Command Pattern: logging requests
    29. Command Pattern in the Real World
    30. Tools for your Design Toolbox
      1. Design Patterns Crossword
3.145.47.253