This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Abstract Factory and Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply 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: 142

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
Bartender

Joined: Sep 08, 2007
Posts: 2928
    
  15

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Abstract Factory and Composition
 
Similar Threads
confused with Design patterns
abstract and abstract factory
When to use Factory and when to use AbstractFactory ?
SCEA Part -I - Questions out desgin pattern
abstract factory - object composition