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.
Which among the following is NOT a member of any of the two Houses of the Indian Parliament?
I. Prime Minister of India Â
II. Finance Mi...
Which of the following pairs is/are correctly matched?
Mars Mission               Country
1. Tianwen-1Â Â ...
National emergency is declared under which of the following articles?
Which of the following statements regarding the electoral rolls is/are correct?
1. There is one general electoral roll for every territorial co...
The Supreme Court is bound to declare a law as invalid if it violates:
1. Fundamental Rights
2. Directive Principles of State Policy
<...Consider the following statements:
1. The Constitution of India only mentions the office of the Chief Election Commissioner (CEC) and not the Ele...
Which of the following is Provisional Parliament of India?
Subansiri Lower Hydro Electric Project (SLHEP) is located on the border of which two states?
With reference to the International Monetary and Finance Committee, consider the following statements:
1. It is the ministerial-level committee o...
Who appoints the Comptroller and Auditor General of India (CAG)?