The Artima Developer Community
Sponsored Link

Books Forum
Head First Design Patterns

21 replies on 2 pages. Most recent reply: Jan 16, 2007 6:41 AM by Glenn Puchtel

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 21 replies on 2 pages [ 1 2 | » ]
Eric Freeman

Posts: 30
Nickname: erictfree
Registered: Apr, 2003

Head First Design Patterns (View in Chapters Library)
by Eric Freeman & Elisabeth Freeman with Kathy Sierra & Bert Bates
Posted: Jan 24, 2005 2:54 PM
Reply to this message Review this Book
Download a Free Chapter

3
The Decorator Pattern
Please login to download.

Buy the Book

About the Book

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.


disney

Posts: 35
Nickname: juggler
Registered: Jan, 2003

Re: Head First Design Patterns Posted: Jan 26, 2005 1:34 AM
Reply to this message Reply
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? ;-)

Eric Freeman

Posts: 30
Nickname: erictfree
Registered: Apr, 2003

Re: Head First Design Patterns Posted: Jan 26, 2005 7:47 AM
Reply to this message Reply
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."

http://www.amazon.com/exec/obidos/dt/assoc/tg/aa/xml/assoc/-/0596007124/ericsbooks04

Best,

Eric

Kelley Harris

Posts: 8
Nickname: kelley
Registered: Aug, 2004

Re: Head First Design Patterns Posted: Jan 26, 2005 10:06 PM
Reply to this message Reply
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.

Eric Freeman

Posts: 30
Nickname: erictfree
Registered: Apr, 2003

Re: Head First Design Patterns Posted: Jan 27, 2005 4:23 PM
Reply to this message Reply
Kelley,

We appreciate the kind words and hearing that the book is working for C++ developers.

We'd love to hear your suggestions for future books as well.

Best,

Eric

Unnikrishnan

Posts: 1
Nickname: unnisworld
Registered: Jul, 2004

Re: Head First Design Patterns Posted: Feb 8, 2005 11:21 AM
Reply to this message Reply
Just now, I read the sample chapters. It looks terrific. I am going to buy this book. Thanks authors for the wonderful work.

I found a small printing mistake,
Page 107, getSize() method misses return type.

atul

Posts: 1
Nickname: atul123
Registered: Jul, 2004

Re: Head First Design Patterns Posted: Feb 18, 2005 12:19 AM
Reply to this message Reply
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 :-)

Zuber Saiyed

Posts: 1
Nickname: cyclob
Registered: Feb, 2005

Re: Head First Design Patterns Posted: Feb 24, 2005 2:56 AM
Reply to this message Reply
This is the best way to elaborate complex topics like design patterns. Freeman's did really a great job.
This book is worthy of remembrance for long.

ranjeet wagh

Posts: 1
Nickname: ranjeetwag
Registered: Feb, 2003

Re: Head First Design Patterns Posted: Feb 24, 2005 4:04 AM
Reply to this message Reply
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

shyam

Posts: 1
Nickname: shyambabu
Registered: May, 2005

Re: Head First Design Patterns Posted: May 30, 2005 7:51 AM
Reply to this message Reply
thanks

Ben Clinkinbeard

Posts: 1
Nickname: bclink
Registered: Jul, 2005

Re: Head First Design Patterns Posted: Jul 7, 2005 6:43 AM
Reply to this message Reply
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.

Christian Flanagan

Posts: 1
Nickname: cflanagan
Registered: Dec, 2005

Re: Head First Design Patterns Posted: Dec 21, 2005 8:29 AM
Reply to this message Reply
Link to PDF file with sample chapter is broken. An error message says that the file is damage.

Ravi Venkataraman

Posts: 80
Nickname: raviv
Registered: Sep, 2004

Re: Head First Design Patterns Posted: Dec 22, 2005 11:25 AM
Reply to this message Reply
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.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Head First Design Patterns Posted: Dec 23, 2005 3:12 PM
Reply to this message Reply
> Later tonight, I'll be posting a simpler solution to the
> problem.

Okay, where is it?

Ravi Venkataraman

Posts: 80
Nickname: raviv
Registered: Sep, 2004

Re: Head First Design Patterns Posted: Dec 26, 2005 1:45 PM
Reply to this message Reply
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.*;
 
public class Beverage {
	private BeverageType beverageType;
	private List<Condiment> condiments = new ArrayList<Condiment> ();
 
	public Beverage (BeverageType bevType)
	{	this.beverageType = bevType;	}
 
	public void addCondiment(Condiment condi)
	{	this.condiments.add(condi);	}
 
	public double getCost() {
		double cost = this.beverageType.getCost();
		for (Condiment c : condiments)
			cost += c.getCost();
		return cost;
	}
}
 
/************************************************/
class BeverageType {
	private static Map<String, BeverageType> allBeverageTypes =
		new HashMap<String, BeverageType> ();
 
	private String name;
	private double 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();	}
 
	public static void 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;	}
 
	public static BeverageType getBeverageType(String bevType)
	{	return allBeverageTypes.get(bevType);
		// Exception handling omitted for simplicity
	}
 
	public double getCost() { return this.cost;	}
}
 
/************************************************/
 
class Condiment {
	// Follows the same pattern as BeverageType.
	private static Map<String, Condiment> allCondiments =
		new HashMap<String, Condiment> ();
 
	private String name;
	private double 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();	}
 
	public static void 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;	}
 
	public static Condiment getCondiment(String condiType)
	{	return allCondiments.get(condiType);
		// Exception handling omitted for simplicity
	}
	public double getCost() { return this.cost;	}
}
 

Flat View: This topic has 21 replies on 2 pages [ 1  2 | » ]
Topic: Rails for Java Developers Previous Topic   Next Topic Topic: Google Maps API

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use