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!