• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Regarding query in BRain power exercise in Head First Design Pattern series by Kathy and Bert

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I was studying Design patterns - Head First book by Bert and Kathy Sierra . On Page no - 176, there is a brain power exercise. Choc-O-Holic has done a decent job of ensuring bad things don’t happen, don’t you think? Then again, you probably suspect that if two ChocolateBoiler instances get loose, some very bad things can happen.How might things go wrong if more than one instance of ChocolateBoiler is created in an application?

I am not able to get what could go wrong. Can anyone please help.

The Chocolate Factory
Everyone knows that all modern chocolate factories have computer-controlled
chocolate boilers. The job of the boiler is to take in chocolate and milk, bring them
to a boil, and then pass them on to the next phase of making chocolate bars.
Here’s the controller class for Choc-O-Holic, Inc.’s industrial strength Chocolate
Boiler. Check out the code; you’ll notice they’ve tried to be very careful to ensure
that bad things don’t happen, like draining 500 gallons of unboiled mixture, or
filling the boiler when it’s already full, or boiling an empty boiler!

 
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always use the code button; I added it to your code and doesn't it look better Unfortunately, you haven't indented your code correctly; you only used one space and that only in a few places. Remember, you will have difficulty if you try to read poorly indented code. Please don't push the enter key after each line; let the screen do its own text wrapping.

I think I can see an error, but I had to look hard for it. Go through every method and work out what the state of the two booleans will be at the end of it. I am not sure I would have called those two isXXX() methods; I might have simply used the fields directly.
 
anchit aggarwal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ritchie,

Thanks. I will keep in mind the indentation part and other things you told. My query was the point which author is asking. What could go wrong if 2 instances of chocolate boiler are created.
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that you need two instances to have a problem. You already have a problem with only one instance, don't you?
 
Bartender
Posts: 10983
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seeing as how the only constructor is private and no one is calling it how is ANY supposed to be created, let alone more than one.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic