Decorator Pattern

I always enjoy good blog posts on patterns.  This week the Los Techies blogger Sean Chambers covers the decorator pattern as part of the Pablo’s Topic of the Month (PTOM).

As always Sean does a good job explaining how the decorator pattern works with code snippets as well.

My favorite part is the explanation of why to use the decorator pattern instead of just a traditional inheritance model:

This would work, however it’s not very desirable. Eventually as you add more and more permutations, (Coffee w/ Espresso, Coffee w/ Espress and Whip cream, etc..) it would lead to a class explosion and you would have a new class for every new combination of ingredients someone could have for a cup of coffee. A better option would be if we could add or "decorate" the original cost and name with our added options. Enter the Decorator Pattern.

Check it out!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s