Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Abstract Factory and Composition

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic