Question
Which design pattern would be most appropriate to ensure
that only one instance of a class exists and provides a global point of access to that instance?ÂSolution
The Singleton Pattern is a design pattern used to restrict a class to only one instance, ensuring that the same instance is globally accessible across the application. This pattern is particularly useful in cases like logging, configuration management, or database connections, where multiple instances could lead to resource conflicts or inefficiencies. The Singleton Pattern is typically implemented by making the class constructor private, defining a static method for instance retrieval, and storing the single instance in a static variable. This setup ensures that the instance is created only once and reused throughout the application, conserving resources and maintaining consistency by providing a unified point of interaction. Option A (Factory Pattern) - The Factory Pattern is focused on creating objects based on input parameters without limiting the number of instances, unlike Singleton, which restricts instantiation. Option C (Observer Pattern) - Observer Pattern establishes a dependency between objects, allowing them to notify others of changes, differing from Singleton’s focus on single-instance enforcement. Option D (Strategy Pattern) - Strategy Pattern is used to select algorithms dynamically at runtime, focusing on behavioral variability rather than instance control. Option E (Decorator Pattern) - The Decorator Pattern enhances objects with additional functionalities dynamically, unrelated to the Singleton goal of limiting instance creation.
In a rectangle, length : breadth = 4 : 3. What is the value of length : diagonal?
In the figure BD = CD = AC, ∠ABC = 27 ° , ∠ACD = y. Find value of x.
In the given Figure, Find  angle BCD. If AB is a diameter & AB is parallel to CD.
The sides of a triangle are 10 cm, 17 cm, and 21 cm. Find the area of the triangle using Heron’s formula.
The radius of the incircle of a triangle is 3 cm. if the area of the triangle is 12 cm 2 , then its perimeter is?
Angles of a triangle are in the ratio 1 : 2 : 3. Find the measure of the largest angle.
If y = 5x + c passes through point A(5, 2), what is the value of c?
...A triangular field has sides measuring 50 m, 78 m, and 112 m. Determine the height of the field corresponding to the longest side and also find the area...
Find the area of triangle having sides 8 m, 9 m, and 13 m.
If I is the incentre of ΔABC , if ∠BAC = 450 , then what is the measure of ∠BIC?