Monday, August 30, 2010

Creational patterns

Ok i will do it! That's what i tell to my colleague sitting behind me when he keep asking me to learn and explain him about creational patterns. I thought it's very boring but once i started reading i liked it very much. Later i came to know that my colleague wanted me to do this because he was preparing for his interviews and was not interested to learn by himself. Anyway thanks to him to keep pushing me for learning this.
Now enough about why i am here, rather i will explain what i am going to explain you and how you can get benefit out of it.
So i am here to tell you something useful about object creational patterns. Usually in our (developers) day to day life we deal with object creation. We are smart enough to get our job done but sometime it become nightmare if you have to maintain your own code or if your manager/client (our god) comes with some change request which needs to be incorporated ASAP. Ok relax no need of quiting your job, just because you does't want to touch anything which is working fine now and soon going to become nightmare of scary bugs for you.


What is Object Creational Pattern?
Ok it is the obvious question that will first come to your mind. In very simple words we can say, object creational pattern like any other pattern is the best way known for creating instance of object in certain specific scenario.


Types of Object Creational Pattern

  • The Factory Pattern is used to choose and return an instance of a class from a number of similar classes based on data you provide to the factory.
  • The Abstract Factory Pattern is used to return one of several groups of classes. In some cases it actually returns a Factory for that group of classes.
  • The Builder Pattern assembles a number of objects to make a new object, based on the data with which it is presented. Frequently, the choice of which way the objects are assembled is achieved using a Factory.
  • The Prototype Pattern copies or clones an existing class rather than creating a new instance when creating new instances is more expensive.
  • The Singleton Pattern is a pattern that insures there is one and only one instance of an object, and that it is possible to obtain global access to that one instance.