• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

doubts on questions #5 self-test Chapter 10

 
Ranch Hand
Posts: 145
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a doubt about the Factory pattern and particularly on the question #5 in the self test.

First I would like to understand if I understand the operation of the Factory pattern.
The main problem, that the use of the pattern tries to solve, is related to the change we want to do to a class to add functionality, in this case a change would also involve changing the main class.
To solve the problem the main class must only interact with an interface or an abstract class so that it does not interact with the class that takes care of the implementation.
This is an example taken from the book (K&B7):


Now we come to the question, I can not see the use of the Factory pattern in this code:


Do you help me to understand?
 
John Lerry
Ranch Hand
Posts: 145
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nobody answers me?
sorry if I put this post but I'm afraid that this thread is not read.
 
Enthuware Software Support
Posts: 4885
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Lerry wrote:
Now we come to the question, I can not see the use of the Factory pattern in this code:


Do you help me to understand?


One would have to stretch the imagination quite a bit to consider the above code as a usage of factory pattern.
 
John Lerry
Ranch Hand
Posts: 145
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the considerations made above on the Factory Pattern is correct I do not see absolutely the application of this pattern in that code.

the solution of the book says this:


Class A is the object we are creating using the factory method. Class G is the abstract superclass for the factory. Not shown is a class implementing class G that actually creates the object.

 
Pay attention! Tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic