Click here to Skip to main content
15,893,266 members
Articles / Programming Languages / C#

Exploring Factory Pattern

,
Rate me:
Please Sign up or sign in to vote.
4.84/5 (63 votes)
23 Jun 2009CPOL13 min read 140K   2.1K   147  
How to Remove Conditional Checks
Features:

1.Factory pattern is one of the types of creational patterns.
  You can make out from the name factory itself it�s meant to 
  construct and create something. 
 
2.In software architecture world factory pattern is meant to 
  centralize creation of objects, there is need for centeralize
  creation of objects because of two generous problem. 
  
  First we have lots of �new�  keyword scattered in the client.
  In other ways the client is loaded with lot of object creational
  activities which can make the client logic very complicated.
  
  Second issue is that the client needs to be aware of all types of
  concerete class.
  
  3. Factory pattern creates the objects without instantiation logic
  to the client.
  
  4. Refers to the newly created object through a common interface.
  

Conclusion:

1.When we design an application just think if we really need it a
factory to create objects. May be using Facory pattern brings unnecessary
complexity in application. Anyway if we have so many object of same base
type and we manipulate them mostly as abstract objects, then we need a
factory.

If we have decided to move for Factory pattern its better to choose one
of the class registeration mechanism, because procedural (noob) imblementation
violates the open and closed principle.

 
 Reference:
 
 http://www.codeproject.com/KB/aspnet/SoftArchInter1.aspx#Canyouexplainabstractfactorypattern
 
 http://www.oodesign.com

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions