Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Eric Freeman, Elisabeth Robson
Head First Design Patterns, 2nd Edition
1. Intro to Design Patterns: Welcome to Design Patterns
It started with a simple SimUDuck app
But now we need the ducks to FLY
But something went horribly wrong...
What happened?
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
Integrating the Duck Behavior
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?
Tools for your Design Toolbox
Design Patterns Crossword
Design Puzzle Solution
Design Patterns Crossword Solution
2. The Observer Pattern: Keeping your Objects in the Know
The Weather Monitoring application overview
Unpacking the WeatherData class
Our Goal
Stretch Goal
Taking a first, misguided SWAG at 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
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
Power up the Weather Station
Looking for the Observer Pattern in the Wild
The Swing library
A little life-changing application
Coding the life-changing application
Meanwhile back at Weather-O-Rama
For the Subject to send notifications...
For an Observer to receive notifications...
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. The Decorator Pattern: Decorating Objects
Welcome to Starbuzz Coffee
The Open-Closed Principle
Meet the Decorator Pattern
Constructing a drink order with Decorators
Okay, here’s what we know about Decorators, so far...
The Decorator Pattern defined
Decorating our Beverages
Cubicle Conversation
New barista training
Writing the Starbuzz code
Coding beverages
Coding condiments
Serving some coffees
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. The Factory Pattern: Baking with OO Goodness
Identifying the aspects that vary
But the pressure is on to add more pizza types
Encapsulating object creation
Building a simple pizza factory
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...
A framework for the pizza store
Allowing the subclasses to decide
Let’s make a PizzaStore
Declaring a factory method
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...
We’re just missing one thing: Pizzas!
Our PizzaStore 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 st yle cheese pizzas?
You’ve waited long enough. Time for some pizzas!
It’s finally time to meet the Factory Method Pattern
The Creator classes
The Product classes
View Creators and Products in Parallel
Design Puzzle
Factory Method Pattern defined
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 PizzaStore...
Ensuring consistency in your ingredients
Families of ingredients...
Building the ingredient factories
Building the New York ingredient factory
Reworking the pizzas...
Revisiting our pizza stores
What have we done?
More pizza for Ethan and Joel...
From here things change, because we are using an ingredient factory
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. The Singleton Pattern: One of a Kind Objects
The Little Singleton
A small Socratic exercise in the st yle of The Little Lisper
Dissecting the classic Singleton Pattern implementation
Patterns Exposed
The Chocolate Factory
Singleton Pattern defined
Hershey, PA, we have a problem...
BE the JVM
Dealing with multithreading
Can we improve multithreading?
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().
Meanwhile, back at the Chocolate Factory...
Congratulations!
Tools for your Design Toolbox
Design Patterns Crossword
BE the JVM Solution
Design Patterns Crossword Solution
6. The Command Pattern: Encapsulating Invocation
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...
Time to write that documentation...
What are we doing?
Time to QA that Undo button!
Using state to implement Undo
Adding Undo to the CeilingFan commands
Get ready to test the ceiling fan
Testing the ceiling fan...
Every remote needs a Party Mode!
Using a macro command
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
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Head First Design Patterns
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset