I am not able to understand the exact differance between factory pattern and abstract factory patttern . I know the difference theoratically but in which situations exactly which pattern to use is not clear. Can somebody explain how to decide if the factory pattern is used or abstract factory pattern is to be used. Thanks
Here is one main difference between the 2 patterns :
1. Use the Factory Method pattern when you are creating just one object and you want to encapsulate the object creation. Basically, you feel that the object creation is an area of change as newer concrete classes could get added later on and hence you want to encapsulate that area of change
2. Use the abstract factory pattern when you want to create a family of dependent objects related to each other in some way. Even for creating one object, you could use the Abstract factory, but that would be overkill. Generally, the factory method using inheritance provides better performance than the AF which uses composition.
Hey, post this question in the OO and patterns forum. We can expect a nice answer from Ilja Preuss. Even I would like to read her answer for this.
Joined: Jan 09, 2006
Hey Sathish , Thanks a lot that was preety well explained.I will surely post thid topic on oo and pattern forum as well.