The Singleton pattern
Tom replied, “There’s not much to say about this one.” Tom made two changes to the WheelchairBuilderDirector
class in the diagram. You can see the changes here:
Figure 6.18: The structure for the Builder pattern used for wheelchairs has been made into a Singleton. You can tell since there’s only a single number on the diagram
“To make this builder a Singleton, I just added the internal reference WheelchairBuilderSingleton
(1). This will hold an instance of WheelchairBuilderDirector
if the object has already been instantiated. Then, I added the GetInstance()
method. This method will check to see whether there is an instance already in WheelchairBuilderSingleton
. If it’s empty, the method creates an instance, stores it in that private variable, and returns the instance. If there’s already an instance there, it returns that one. I’m not sure we get anything from making it a singleton...