ISBN: 0596007124
Publisher: O'Reilly Media, Inc.
Publication Date: November, 2004
Edition: 1st
Binding: Paperback
Number of Pages: 638
Advertisement
You're not alone. At any given moment, somewhere in the world someone struggles with the same software design problems you have. You know you don't want to reinvent the wheel (or worse, a flat tire), so you look to Design Patterns--the lessons learned by those who've faced the same 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 else. Something more challenging. Something more complex. Something more fun.
You want to learn about the patterns that matter--why to use them, when to use them, how to use them (and when NOT to use them). But you don't just want to see how patterns look in a book, you want to know how they look "in the wild". In their native environment. In other words, in real world applications. You also want to learn how patterns are used in the Java API, and how to exploit Java's built-in pattern support in your own code. You want to learn the real OO design principles and why everything your boss told you about inheritance might be wrong (and what to do instead). You want to learn how those principles will help the next time you're up a creek without a design paddle pattern.
Most importantly, you want to learn the "secret language" of Design Patterns so that you can hold your own with your co-worker (and impress cocktail party guests) when he casually mentions his stunningly clever use of Command, Facade, Proxy, and Factory in between sips of a martini. You'll easily counter with your deep understanding of why Singleton isn't as simple as it sounds, how the Factory is so often misunderstood, or on the real relationship between Decorator, Facade and Adapter. With Head First Design Patterns, you'll avoid the embarrassment of thinking Decorator is something from the "Trading Spaces" show. Best of all, in a way that won't put you to sleep!
We think your time is too important (and too short) to spend it struggling with academic texts. If you've read a Head First book, you know what to expect--a visually-rich format designed for the way your brain works. Using the latest research in neurobiology, cognitive science, and learning theory, Head First Design Patterns will load patterns into your brain in a way that sticks. In a way that lets you put them to work immediately.In a way that lets you put them to work immediately. 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.
I haven't read the book, but a look at the listed index says it's a guided tour of the GoF book. Is that a major need in my life, or in the life of patterns? I suspect not. Perhaps I have the wrong idea, and reading the book would convince me it's the best thing since, er, design patterns? ;-)
Hi Steve, you might peruse the Amazon reviews to get a feel for the book. I think you'll find that many developers have found it very useful and not a "tour of GoF."
I'm greatly enjoying the book. (on page 135 out of 629) It presents design patterns in the context of the design principles that motivate the patterns. (Somewhat like Robert Martin's Agile Development book.) It's more of a workbook relative to the reference/catelog nature of the GOF book. It's fun writing. A great deal.
Check out the praise for the book by Eric Gamma, Richard Helm, Ward Cunningham, etc.
The examples are in java, but C++ developers can follow along just fine.
I personally look forward to more writing from these authors.
This is a superb book. I am reading it off and on. The decorator stuff is too good. I bought it in a bookshop and just got hooked to it. The next day I visited the bookshop again and got "Head First Java".. ( Haven't started reading that one but that too looks great ).... Happy writing authors... waiting for the next round of pages :-)
hi, interesting book ever seen on technical subject[remember (A Brief History of Time -Stephen Hawking )]. was trying gof4 book ...Finaly head first helped me..Easily Grasped design patterns I hope head first series will be available for dot net (c#) developers
I just finished this book and I can honestly say its one of the best technical books I've ever read. Now for the shocker: I am a web developer. Never done real software development in my life. I actually related the code examples to Actionscript without much problem at all.
I have browsed articles on Design Patterns here and there before but never understood much of it. This book is as close as you can get to sitting and talking with someone who knows the material which, in my opinion, would be the ideal way to learn a topic. This book was so good it made me want to play around with JSP and Java. I just finished the book a few days ago and am now starting my second read of the book.
I looked at the example and feel that the solution provided is far too complex. There is a simpler way to solve the given problem that is also more flexible.
I feel that having Condiment class have the same "interface" as the Beverage class is bad design. A Condiment is not a Beverage. Any solution that forces me to say that a Condiment is a Beverage doesn't sound right. Hence, I dislike the suggested approach of using a Decorator to solve the problem.
Later tonight, I'll be posting a simpler solution to the problem.
The problem as stated in the book excerpt is simply one of finding the total cost of a beverage of a specified type (Mocha, Espresso, etc.) when an arbitrary number of "condiments" can be added to any drink, with the price of each beverage and condiment being known.
In this case, I do not think the Decorator pattern is needed. Anyway, the fact that Decorators need to have the exact same interface as the main class suggests that unnecessary duplication is taking place.
So, here's the code. Nothing fancy. Just ordinary composition without any inheritance at all.
In this design, to add any new beverage type, it is just necessary to modify the data source, and execute the loadAllBeverageTypes static method of the Beverage Type class. The same holds for Condiments. The good thing is that no code needs to be changed, and the data can be updated while the applciation is running!
package decorator;
import java.util.*;
publicclass Beverage {
private BeverageType beverageType;
private List<Condiment> condiments = new ArrayList<Condiment> ();
public Beverage (BeverageType bevType)
{ this.beverageType = bevType; }
publicvoid addCondiment(Condiment condi)
{ this.condiments.add(condi); }
publicdouble getCost() {
double cost = this.beverageType.getCost();
for (Condiment c : condiments)
cost += c.getCost();
return cost;
}
}
/************************************************/
class BeverageType {
privatestatic Map<String, BeverageType> allBeverageTypes =
new HashMap<String, BeverageType> ();
private String name;
privatedouble cost;
// Get the name and cost of each condiment from some data source.
// The data source can be an XML file, text file, or a database, etc.
static { loadAllBeverageTypes(); }
publicstaticvoid loadAllBeverageTypes(){
//for (String nameAndCost : nameAndCostDataSourceArray) {
// get name and cost from data source string
// allBeverageTypes.put(name, newBeverageType(name, cost));
}
private BeverageType(String name, double cost)
{ this.cost = cost; this.name = name; }
publicstatic BeverageType getBeverageType(String bevType)
{ return allBeverageTypes.get(bevType);
// Exception handling omitted for simplicity
}
publicdouble getCost() { return this.cost; }
}
/************************************************/
class Condiment {
// Follows the same pattern as BeverageType.
privatestatic Map<String, Condiment> allCondiments =
new HashMap<String, Condiment> ();
private String name;
privatedouble cost;
// Get the name and cost of each condiment from some data source.
// The data source can be an XML file, text file, or a database.
static { loadAllCondiments(); }
publicstaticvoid loadAllCondiments(){
//for (String nameAndCost : nameAndCostDataSourceArray) {
// get name and cost from data source string
// allCondiments.put(name, newCondiment(name, cost));
//
// Put all this into a method called loadAllCondiments();
}
private Condiment(String name, double cost)
{ this.cost = cost; this.name = name; }
publicstatic Condiment getCondiment(String condiType)
{ return allCondiments.get(condiType);
// Exception handling omitted for simplicity
}
publicdouble getCost() { return this.cost; }
}
Flat View: This topic has 21 replies
on 2 pages
[
12
|
»
]