Lecture13 - Turn the following ChocolateBoiler class into singleton public class ChocolateBoiler cfw private boolean empty private boolean boiled public

Lecture13 - Turn the following ChocolateBoiler class into...

This preview shows page 1 - 4 out of 10 pages.

Turn the following ChocolateBoiler class into singleton: public class ChocolateBoiler { private boolean empty; private boolean boiled; public ChocolateBoiler() { empty = true; boiled = false; } public void fill() { if(empty == true) { empty = false; boiled = false; } } } To enforce singleton-ness, A single constructor, which is private or protected and parameterless. This prevents other classes from instantiating it. A static variable holds a reference to the single created instance. 1
Image of page 1
2
Image of page 2
You have a subsystem that consists of multiple classes, making it hard to use. Additionally, the implementation of many of the classes is likely to change, but the interfaces are stable. You want to make it easy for the users of this subsystem to work with it. What design pattern might you apply to facilitate this? Company X has a large amount of software applications written using a particular class library. Let the class library contains the classes AYand BY. Let the class AYcontains a single method ay()the class BY and
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture