my dog learned polymorphism*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Abstract Factory and Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Abstract Factory and Composition" Watch "Abstract Factory and Composition" New topic
Author

Abstract Factory and Composition

Adolfo Eloy
Ranch Hand

Joined: Mar 21, 2009
Posts: 146

Hi all.

I'm studying about patterns with the "Head First Design Patterns Book".
At the factory pattern chapter, one bullet point says: "Abstract Factory relies on object composition"

I'd like to get clear where the composition is being done with Abstract Factory.
I always saw composition when an aggregation is present when modeling a class.

Thank you folks!

Adolfo Eloy
Software Developer
OCPJP 6
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

I think Authors there were trying to convey that "Abstract Factory" is used in a context of composition, for example you pass in a instance of Abstract Factory Implementation and then make use of the instance to create different other objects. In case of Factory Pattern you make use of some implementation to get an instance and then after that you need not keep the reference to the factory implementation, but in Abstract Factory you create instances of related objects and hence would like to keep the reference to the factory and one way of doing that is by making the reference part of the class (which is composition).
I think the example there clearly states the differences.


Mohamed Sanaulla | My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract Factory and Composition