Question: Answer below questions regarding the Singleton pattern: (3 points) Singleton can initialize the class in two different approaches; eager initialization, lazy initialization, a) what is

Answer below questions regarding the Singleton pattern:

  1. (3 points) Singleton can initialize the class in two different approaches; eager initialization, lazy initialization, a) what is the difference between them in terms of the following: when initialization happen, resource usage, and whether it is thread safe or not .

  2. (5 points) Suppose that you have class called CDRomDriver and you want to make that that there is only one instance of this class. Write code for this class that manages the one instance using the lazy initialization and make sure that this instance is thread-safe

  3. (2 points) Write code to show how class TestDrive can get an instance from CDRomDriver

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!