• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

AbstractFactory Vs Prototype

 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading the GoF book. There it was mentioned how the Prototype pattern can avoid the necessity of a parallel class hierarchy of Abstract and Concrete factories by sending the prototypical instance to the constructor of the only factory class required. Then he talks about how the new object gets created by cloning the prototype. The problems of objects being able to support the cloning effectively were also discussed.
My question is -
If prototype pattern is going to solve some of the cumbersome approaches of AbstractFactory, then when would people prefer to go for AbstractFactory against the choice of prototyping??
The reasons i can see are given below -
1) the problems with deep cloning, sharing common references to other objects, etc.
2) Abstract factory automatically enforces that all the objects being generated by a given factory belong to the same family, once the client creates the proper concrete factory. I guess this is not ensured in the prototype pattern wherein the client can give apples and oranges if they just conform to the interfaces supplied to the constructor of the concrete factory object.
Please let me know if any of the above observations are flawed and also there are some other pros and cons b/w choosing a pattern from the above two.
Thanks,
Jayadev.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The AbstractFactory is also more flexible in some regards - for example I could imagine a factory reading classnames from a configuration file or the like.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic