Posts

Showing posts from May, 2010

Design Pattern in Ruby 1: Decorator pattern

Image
Decorator pattern , something that gives you two type of things A plain vanilla cake and  Cream, cheery etc to decorate the cake :D How does it sounds? Mouth watering design pattern right? Anyway, dont get too excited!! we're gonna dive into the code shortly 8( You might have already known all the nuts and bolts about this pattern, but I was really wondering about the implementation of this pattern in Ruby.  Here I will work with the example given in Head first design patterns (Chapter 3) . There they gave the example of a coffee house. Like our plain vanilla cake, the coffee house also have two different type of things: Beverages: HouseBlend, DarkRoast, Espresso and Decaf Condiments: Milk, Mocha, Soy and Whip So that you can have a DarkRoast with some Mocha and Soy :) However, I think we should have a look at the class diagram first Notice that, here all concrete beverages are inherited from the abstract class Beverage . And all concrete condiment cla