Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Factory and Composition

 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic