You are designing a class library by using the .NET Framework 3.5 and Microsoft SQL Server 2008. The class library will be used by several .NET applications. The class library will contain a utility class that executes advanced mathematical operations. You need to design the utility class to meet the following requirements:
It can be accessed only by other classes in the same .NET assembly.
It can be instantiated only once.
What should you do?
A.
Create a public class along with an internal constructor.
B.
Create an internal class along with an internal constructor.
C.
Create a public class along with a private constructor.
Expose a public static method that returns an instance of the class.
D.
Create an internal class along with a private constructor.
Expose an internal static method that returns an instance of the class.
Explanation:
Since the class can only be instantiated once, the Design Pattern that must be implemented is the Singleton pattern. In the Singleton pattern, a private or internal static method is used to return an instance of the class. This option is only available in answer choice D.