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.
Publisher resources
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?
- We know what you’re thinking.
- And we know what your brain is thinking.
- Metacognition: thinking about thinking
- Here’s what WE did:
- Here’s what YOU can do to bend your brain into submission
-
Read Me
- 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.
- Tech Reviewers
- Tech Reviewers, 2nd Edition
- Acknowledgments
- Acknowledgments
-
1. Welcome to Design Patterns: Intro to Design Patterns
- 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
-
2. Keeping your Objects in the Know: The Observer Pattern
- 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
- Coding the life-changing application
- there are no Dumb Questions
- Meanwhile, back at Weather-O-Rama
- Code Magnets
- Test Drive the new code
- Tools for your Design Toolbox
- Design Principle Challenge
- Design Patterns Crossword
- Design Principle Challenge Solution
- Code Magnets Solution
- Design Patterns Crossword Solution
-
3. Decorating Objects: The Decorator Pattern
- Welcome to Starbuzz Coffee
- The Open-Closed Principle
- there are no Dumb Questions
- Meet the Decorator Pattern
- Constructing a drink order with Decorators
- The Decorator Pattern defined
- Decorating our Beverages
- Cubicle Conversation
- New barista training
- Writing the Starbuzz code
- Coding beverages
- Coding condiments
- Serving some coffees
- there are no Dumb Questions
- Real-World Decorators: Java I/O
- Decorating the java.io classes
- Writing your own Java I/O Decorator
- Test out your new Java I/O Decorator
- Tools for your Design Toolbox
-
4. Baking with OO Goodness: The Factory Pattern
- 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
- A framework for the pizza store
- Allowing the subclasses to decide
- Let’s make a Pizza Store
- Declaring a factory method
- We’re just missing one thing: Pizzas!
- You’ve waited long enough. Time for some pizzas!
- It’s finally time to meet the Factory Method Pattern
- View Creators and Products in Parallel
- Design Puzzle
- Factory Method Pattern defined
- there are no Dumb Questions
- Looking at object dependencies
- The Dependency Inversion Principle
- Applying the Principle
- Inverting your thinking...
- A few guidelines to help you follow the Principle...
- Meanwhile, back at the Pizza Store...
- Families of ingredients...
- Building the ingredient factories
- Building the New York ingredient factory
- Reworking the pizzas...
- Reworking the pizzas, continued...
- Revisiting our pizza stores
- What have we done?
- More pizza for Ethan and Joel...
- Abstract Factory Pattern defined
- Factory Method and Abstract Factory compared
- Tools for your Design Toolbox
- Design Patterns Crossword
- Design Puzzle Solution
- Design Patterns Crossword Solution
-
5. One-of-a-Kind Objects: The Singleton Pattern
- The Little Singleton
- Dissecting the classic Singleton Pattern implementation
- The Chocolate Factory
- Singleton Pattern defined
- Hershey, PA, we have a problem...
- BE the JVM
- Dealing with multithreading
- Can we improve multithreading?
- Meanwhile, back at the Chocolate Factory...
- Congratulations!
- there are no Dumb Questions
- Tools for your Design Toolbox
- Design Patterns Crossword
- Design Patterns Crossword Solution
-
6. Encapsulating Invocation: The Command Pattern
- 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
- Time to write that documentation...
- What are we doing?
- Time to QA that Undo button!
- Using state to implement Undo
- Adding Undo to the Ceiling Fan commands
- Get ready to test the ceiling fan
- Testing the ceiling fan...
- Every remote needs a Party Mode!
- Using a macro command
- there are no Dumb Questions
- More uses of the Command Pattern: queuing requests
- More uses of the Command Pattern: logging requests
- Command Pattern in the Real World
- Tools for your Design Toolbox
- Design Patterns Crossword
-
7. Being Adaptive: The Adapter and Facade Patterns
- 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
- there are no Dumb Questions
- Adapter Pattern defined
- Object and class adapters
- Duck Magnets
- Duck Magnets Answer
- Real-world adapters
- Adapting an Enumeration to an Iterator
- And now for something different...
- Home Sweet Home Theater
- Watching a movie (the hard way)
- Lights, Camera, Facade!
- there are no Dumb Questions
- Constructing your home theater facade
- Implementing the simplified interface
- Time to watch a movie (the easy way)
- Facade Pattern defined
- The Principle of Least Knowledge
- How NOT to Win Friends and Influence Objects
- there are no Dumb Questions
- The Facade Pattern and the Principle of Least Knowledge
- Tools for your Design Toolbox
- Design Patterns Crossword
- Design Patterns Crossword Solution
-
8. Encapsulating Algorithms: The Template Method Pattern
- 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
- there are no Dumb Questions
- The Hollywood Principle
- The Hollywood Principle and Template Method
- there are no Dumb Questions
- Template Methods in the Wild
- Sorting with Template Method
- We’ve got some ducks to sort...
- What is compareTo()?
- Comparing Ducks and Ducks
- Let’s sort some Ducks
- The making of the sorting duck machine
- there are no Dumb Questions
- Swingin’ with Frames
- Custom Lists with AbstractList
- Design Patterns Crossword
- Tools for your Design Toolbox
- Design Patterns Crossword Solution
-
9. Well-Managed Collections: The Iterator and Composite Patterns
- 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?
- Implementing the spec: our first attempt
- What now?
- Can we encapsulate the iteration?
- Meet the Iterator Pattern
- Adding an Iterator to DinerMenu
- Reworking the DinerMenu with Iterator
- Fixing up the Waitress code
- Testing our code
- What have we done so far?
- Reviewing our current design...
- Making some improvements...
- there are no Dumb Questions
- Cleaning things up with java.util.Iterator
- We are almost there...
- What does this get us?
- Iterator Pattern defined
- The Iterator Pattern Structure
- The Single Responsibility Principle
- there are no Dumb Questions
- Meet Java’s Iterable interface
- Java’s enhanced for loop
- Not so fast; Arrays are not Iterables
- Taking a look at the Café Menu
- Reworking the Café Menu code
- Adding the Cafe Menu to the Waitress
- Breakfast, lunch, AND dinner
- What did we do?
- We decoupled the Waitress....
- ...and we made the Waitress more extensible
- But there’s more!
- Iterators and Collections
- Code Magnets
- Is the Waitress ready for prime time?
- Just when we thought it was safe...
- What do we need?
- The Composite Pattern defined
- there are no Dumb Questions
- Designing Menus with Composite
- Implementing MenuComponent
- Implementing the MenuItem
- Implementing the Composite Menu
- Getting ready for a test drive...
- Now for the test drive...
- Getting ready for a test drive...
- Design Patterns Crossword
- Tools for your Design Toolbox
- Code Magnets Solution
- Design Patterns Crossword Solution
-
10. The State of Things: The State Pattern
- 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
-
11. Controlling Object Access: The Proxy Pattern
- Coding the Monitor
- Testing the Monitor
- Adding a remote proxy to the Gumball Machine monitoring code
- Remote methods 101
- How the method call happens
- Java RMI, the Big Picture
- Making the Remote service
- Step one: make a Remote interface
- Step two: make a Remote implementation
- Step four: start the service
- Step four: start the service
- there are no Dumb Questions
- Complete code for the server side
- Complete code for the client side
- Back to our GumballMachine remote proxy
- Getting the GumballMachine ready to be a remote service
- Registering with the RMI registry...
- Now for the GumballMonitor client...
- Writing the Monitor test drive
- Another demo for the CEO of Mighty Gumball...
- The Proxy Pattern defined
- Get ready for the Virtual Proxy
- Displaying Album covers
- Designing the Album Cover Virtual Proxy
- Writing the Image Proxy
- Testing the Album Cover Viewer
- What did we do?
- there are no Dumb Questions
- Using the Java API’s Proxy to create a protection proxy
- Geeky Matchmaking in Objectville
- The Person implementation
- Five-minute drama: protecting subjects
- Big Picture: creating a Dynamic Proxy for the Person
- Step one: creating Invocation Handlers
- Creating Invocation Handlers, continued...
- Step two: creating the Proxy class and instantiating the Proxy object
- Testing the matchmaking service
- Running the code...
- there are no Dumb Questions
- The Proxy Zoo
- Design Patterns Crossword
- Tools for your Design Toolbox
- Design Patterns Crossword Solution
- The code for the Album Cover Viewer
-
12. Patterns of Patterns: Compound Patterns
- 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
- Meet Model-View-Controller
- A closer look...
- there are no Dumb Questions
- Understanding MVC as a set of Patterns
- Observer
- Strategy
- Composite
- Using MVC to control the beat...
- Putting the pieces together
- Building the pieces
- Now let’s have a look at the concrete BeatModel class
- The View
- Implementing the View
- Now for the Controller
- Putting it all together...
- Exploring Strategy
- Adapting the Model
- Now we’re ready for a HeartController
- And now for a test run...
- there are no Dumb Questions
- Tools for your Design Toolbox
- Exercise Solutions
-
13. Patterns in the Real World: Better Living with Patterns
- 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.
- Your Mind on Patterns
- Don’t forget the power of the shared vocabulary
- Cruisin’ Objectville with the Gang of Four
- Your journey has just begun...
- The Patterns Zoo
- Annihilating evil with Anti-Patterns
- Tools for your Design Toolbox
- Leaving Objectville...
- Boy, it’s been great having you in Objectville.
-
A. Leftover Patterns
- Bridge
- Why use the Bridge Pattern?
- Builder
- Why use the Builder Pattern?
- Chain of Responsibility
- How to use the Chain of Responsibility Pattern
- Flyweight
- Why use the Flyweight Pattern?
- Interpreter
- How to implement an interpreter
- Mediator
- Mediator in action...
- Memento
- The Memento at work
- Prototype
- Prototype to the rescue
- Visitor
- The Visitor drops by
- Index
Product information
- Title: Head First Design Patterns, 2nd Edition
- Author(s):
- Release date: December 2020
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492078005
You might also like
book
Learning Domain-Driven Design
Building software is harder than ever. As a developer, you not only have to chase ever-changing …
book
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization …
book
Designing Data-Intensive Applications
Data is at the center of many challenges in system design today. Difficult issues need to …
book
Learning Go, 2nd Edition
Go has rapidly become the preferred language for building web services. Plenty of tutorials are available …