- The original test is run before either singleton variation is introduced.
- The observed instance behavior is retained for comparison with the lazy and eager implementations.
7.4 Singleton Pattern Lab
This assignment is based off of the Head First Designs book p. 170-186
Work through the stories in order. Use the acceptance criteria to check each feature, and complete the nested tasks using the specified names, values, and scenarios.
This application is only 3 classes: Program, EagerSingleton, and Lazy Singleton. In the start code, both Eager and Lazy Singleton have the same code.
Check if the instance field object is null.
If it is, assign the instance field to a new instance of the LazySingleton class, passing in "Lazy Singleton Instance 1: " and a new Random(1).Next(2000)
Return the instance.
LazySingleton ls = LazySingleton.GetInstance();Start the application. The first set of numbers will be different, but in the second set of numbers, the Lazy Singleton will be the same instance/number of the first set.
Define a private static field of type EagerSingleton named instance and instantiate it on the same line, passing in "Eager Singleton Instance 1: " and new Random(2).Next(2000)
Return to each story and verify its acceptance criteria. Preserve the submission format and destination stated in the activity; a reading, setup guide, lab, video demonstration, and oral final may require different evidence.
Test the application. Implement the Lazy Singleton pattern. Implement the Eager Singleton pattern.