Tuesday, February 19, 2008

Real life example of Factory Method Design Pattern

Hi,

When i read any design pattern i would like to have some real life example to get that easily. Today i was going throug Factory Method design pattern from
http://www.dofactory.com/Patterns/PatternFactory.aspx and looking for one good example. Finally i found a good one and now i am sharing that with you.

A non-software example that demonstrates this pattern would be a restaurant. Restaurants serve a variety of items which they list in the menu. The restaurant's waiter provides a menu to the customer and, based on the items available in the Menu, the customer selects the items and orders them. These selected items are prepared and served to the customer by the waiter.
If you map this non-software example against the factory design pattern, we can say:
Items, as the subclasses, are served to the customer by a waiter and its preparation is hidden from the customer.
The waiter, as the Factory class, takes the customer's order based on the items available in the menu and serves them.
The customer, as the Client code, orders the items and does not see how the items are prepared.

Hope this will help you to understand the implementation of this pattern.

/Zaq

No comments: