Factory Patterns... Abstract Factory, Factory Method, Simple Factory...
I have an object model specifically for seeing how I could implement the Factory patterns. I would like any comments or any alternatives or suggestions to improve on this design. I have a couple question below the code.
The model is simple enough and is a representation of a business phone. You have an agent login to participate in call distribution, ringer tone (ringtone) and phone properties. The high level structure is as follows:
1. This utilizes the Factory Method pattern since I have the "Parse" function that returns a new object, right?
2. Since I do not have direct values that do not require additional processing I wanted to remove passing XML to the constructor. I thought this is exactly what a Factory is for. Typically I only use a contruction if I have actual valid property values that do not require extra work?
3. I cannot be for certain, but would this be considered a Abstract Factory? What would be required to make it so? I know I could use an Interface, but wanted to keep the methods as Shared/Static and you cannot have a SharedVirtual signature in an Interface. The reason I wanted them shared is becuase it looks cleaner and do not need to instanciate the Factory objects to return the various status objects. Does this even matter, is there a preference?
4. What other creational patterns would be better suited? Builder?
5. Any other suggestions on the model design?
Net Wreck, Sep 14, 2010
1. The intent of factory method pattern is to "Define an interface for creating an object, but let subclasses decide which class to instantiate". Whereas when if i see the source code AgentStatusFactory class defining the "Parse" function and returning the instance of AgentStatus class. After checking the source code i would say this is just a variation of factory method pattern which we can call it as simple factory pattern. If the mentioned structure is changed according to enclosed class diagram, it will turned to be factory Method pattern.
2. Yes the mentioned point is correct.
3.Factory Method Pattern provides an interface for creating an object, but let subclasses decide which class to instantiate. Whereas Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete class. Please refer to following URL.
4. For the given scenario Factory Method pattern is best. Builder has to be used when the creation process is tedious and has to be reused. In other words Builder design pattern has to be used when the creation of a specific object has to be done over several steps.
5. I think given the secnario the above code snippets looks good in many ways maintainability/reusability. But if you could provide more information or goal you want to achieve, it would be helpful.
Saurabh Saxena, Sep 15, 2010