It’s almost close to some 18 years since the GOF came up with a book on design principles. The intent was to capture the reusable aspect of design patterns and appreciate the class of problems these design pattern address. One can assume that by now the whole fraternity of developers and designers across all the various technology domain should have mastered these design patterns, if not all then at least some common ones. The irony is we are still away from that. The very question which comes to mind is, WHY? In this blog I am not intending to provide the solution as to how one should learn design patterns. My intention is to reflect upon why, what and how of design patterns. The motivation is teach myself.
Oh the Abstract Factory!…
I find it a little awkward to use “Abstract Factory” when in real world every factory is for real and produces real products. It is a little tough to imagine an abstract product coming out of an abstract factory. This very abstract product is directly consumable adds to my uneasiness. Too much abstraction but this is what I think the objective is. Create reusable abstract patterns which can fit most of the situation.
Example/Scenario
I live in a place where it rains in the rainy season, snows in winter and hot and sunny in summers. I need different kind of cloths to protect my self from the elements. To do so I go to the store near my house and ask for clothing/item to to protect my self. The store keeper give me the appropriate item as per the environment and depth of my pocket. The items he gives me are of same level of quality and price range. Since he is aware of my standards its easy for him to do so. But when a rich guy from across the street comes up with the same requirements he gets an expensive, branded item. One noticeable thing is all the items he gives to me complement each other in term quality, standard, cost. One can say they go with each other. Same is the case with the items this rich guy gets.
So by looking at above scenario, I now appreciate the efficiency of the shop keeper. I can replace this shopkeeper with and Abstract Shop. The items we get with abstract items and me and the rich as perspective clients. All we need is our product/item suiting to our need.
Now I can easily see my self considering an online store which provides a set of services to its numerous clients. Each client belongs to either of the three group. When a premium group user opens up the site he gets great UI, highly customised advertisement pane, more options in the menus etc. These same set of features are presented to gold user but the functionality in the menu is less, advertisements are mostly relevent. slightly less agronomic UI. Lastly my kind of user, a ‘free group’ users, I am just served enough so that I do not get offended. The UI is bare minimum, advertisements are way off track so much so that I do not know what comes in it, lastly the menu has only log out.
If I get a chance to build something like this website I would definitely consider Abstract Factory Pattern.
Abstract Products : Advertisement Pane, Menu, UI painter.
Abstract Factory : Web Store User Experience
Concreate Factory: Premium User Experience, Gold User Experience, General User Experience.