locked
Advanced Factory Pattren RRS feed

  • Question

  • Hello,

    I am new to design pattrens. I have good Idea on simple  factory pattrens. But I would like to know advanced factory pattren with

    Activator.CreateInstance class.

    Any on could post a sample for Advanced factory pattren.

    Thank you!
    Venkat



    venkat
    Tuesday, August 25, 2009 1:42 PM

All replies

  • By any chance do you mean "Abstract Factory Pattern" and not "Advance"?
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Tuesday, August 25, 2009 2:54 PM
  • I am looking more decoupled Factory pattren insted of a simple one. like creating objects dynamically..

    venkat
    Tuesday, August 25, 2009 3:03 PM
  • How about this:

    http://www.codeproject.com/KB/architecture/CSharpClassFactory.aspx?display=Print

    Hope this helps.
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Tuesday, August 25, 2009 4:50 PM
  • I don't have any examples, but have designed this sort of thing a number of times in the past, to great effect.

    You need the following components:

    - A provider configuration component, which will read a configuration that describes the objects and classes that will be instantiated (this in its simplest form would be a full assembly reference string, as used by the Activator you mention)
    - A base class functionality of functionality to use already instantiated objects stored in memory, or use the component above to instantiate new ones and store them in memory

    Once you have those classes, you can go ahead and create different implementations.

    Additionally, and I'm guessing this is what you're actually asking for is then to use this pattern, along with a strategy pattern, to implement what is known as a provider pattern.  With this you would tie a particular set of implementations to an interface, and have some sort of a management class that will only deal with this interface, and so will return the implementation from your factory above, through the interface reference.
    In this way the management class can be called via a similar interface, and it can pick up multiple, and / or selected implementations of that interface, based on logic that you design.  This could be logic within the class, or my preference is to write a simple business rules engine to all the rules to be defined elsewhere as to which implementation is selected.

    Through this post, when I mention interfaces, these can be an actual interface, or could equally be an abstract class.  Personally, if using an abstract class, I still prefer to use an interface to reference that class or functionality.

    I hope this helps, and sorry that I couldn't give you the implementation, but finding out the hard way is all part of the fun, right?

    Martin.

    MCSD, MCTS, MCPD. Please mark my post as helpful if you find the information good!
    Tuesday, August 25, 2009 8:55 PM