Meaningless Drivel is fun!*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes advantages with  AbstractFactory Design Pattern over Factory Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "advantages with  AbstractFactory Design Pattern over Factory Pattern" Watch "advantages with  AbstractFactory Design Pattern over Factory Pattern" New topic
Author

advantages with AbstractFactory Design Pattern over Factory Pattern

vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 89
Hi all,

I just started Reading design patterns, understood well about the Factory pattern. So i red the disadvantage of factory pattern is if We add any class to heirarchy then we should modify the factory class.




In the above code if add "CreditCardAccount" to Account heirarchy then i should modify the Account factory class.so it is violation of open closed principle.

so as per the abstract factory pattern defination it is factory for factories


In the above code i have two issues.
If add a new branch like "CreditCardAccount"(which is base for CreditCardClassic and CreditCardPremier) which extends Account then i have to modify the Factory Creator class,
If add a BusinessAccount as a child (CheckingBusinessAccount and SavingsBusinessAccount) then i have to modify the AccountFactory class to add a method getBusinssAccount() method.So it also a violation of open closed princlple.

So what is the Use of using AbstractFactory over Factory pattern?The only thing i observed is if the above AbstractFactory example changed to Factory Pattern then in side the Factory class i have to write so many if else conditions.
can anybody explain in simple terminology?(not expecting too much technical terminology)

nit sin
Greenhorn

Joined: Oct 22, 2012
Posts: 6
Design pattern is basically deals with the intent/motivation and kind of issue your are tying to resolve.
Abstract factory provides the abstraction to get the factory of product and factory pattern provides the abstraction to get the concrete product.
hope this clarifies..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: advantages with AbstractFactory Design Pattern over Factory Pattern