Geeks With Blogs


Post Categories

Mahesh Anandan blog

In my opinion, This is the most simplist design pattern of all and the most widely and incorrectly used pattern in both .NET and J2EE World.

Factory and Abstract Factory are two different patterns, .For Example, Abstract factories can be used to instantiate a Concrete Factory. 

What qualifies a Factory:

  1. Co-ordinated Instantiation.
  2. Stateless
  3. Configurable
  4. Can be Secured
  5. Loosely coupled.
  6. Does not Act as Container / not Initiate Transaction. (some of you may disagree with me on this)

In .NET System.Activator & System.Runtime.Remoting.ObjectHandle classes is the right way to implement Factory (or Abstract Factory) pattern.  Frameworks such as Spring, Castle etc., provide these implementation declaratively with Aspects.

For instance in, 

  <object name="DomainObjectImplementationClass"
            type="ImplementationClass1, SpringDIExample" />

You may delaratively specify the factory requirement. When you don't make your factory / abstract factory implementation configurable, chances are you may end up with boilerplate factory creation code over and over again. Spring.NET, Castle etc., is an example of a framework that provides this support via Dependeny Injection thur a container.

What about Containers?

Simply put, Containers provide ability to wrap objects with other statefull services. You may even assume a container as a Controller/Facade layer. This provides loose coupling for the contained objects from becoming “aware of“ details such as Transactionality  , security etc.,

Those Services contained / Managed by the Containers can be instantiated using a Factory. Such containers & Services are not only well defined and truely encapuslated , they are also avoild the application or service specific code from getting scattered all over the application.

Factories , DIs are great concepts to explore, DI's and Factories enables you to develop a product with high cohesion and loose coupling, which essentially translates to maintanibility and scalability.







Posted on Wednesday, August 23, 2006 2:48 PM | Back to top

Comments on this post: Factories , DIs etc.,

# re: Factories , DIs etc.,
Requesting Gravatar...
Thanks for a consice view of factories and containers.. I am learning framework and have mixed feelings about it. like to hear your views.. And thanks for pointing me to System.activator, it saved a lot of code and a great strategy for factories in .NET.

got your page bookmarked, keep em comin..

Ps. can you include your blogspot site as a link in this page, Sphere calculation strategy saved me from many late nights.
Left by seatacgirl on Aug 24, 2006 2:56 PM

# re: Factories , DIs etc.,
Requesting Gravatar...
its so cool baby
Left by seo template on Aug 07, 2010 3:08 PM

Your comment:
 (will show your gravatar)

Copyright © Mahesh Anandan | Powered by: