Question
Which design pattern is best suited for ensuring that a
class has only one instance and provides a global point of access to it?Solution
The Singleton Pattern ensures that a class has only one instance and provides a global point of access to it. It is often used for managing shared resources like a database connection pool, logging, or configuration settings. This pattern works by restricting the class's instantiation and providing a static method to get the single instance. Singleton is particularly useful when exactly one object is required to coordinate actions across the system. This pattern is implemented by making the constructor private, storing the single instance as a static property, and providing a public static method to access it. It ensures thread safety and lazy initialization in multi-threaded applications when implemented carefully. Explanation of Incorrect Options: A) Factory Pattern : The Factory Pattern focuses on creating objects without specifying their exact classes. It abstracts the instantiation process, allowing for flexibility in object creation. However, it does not restrict the number of instances or provide a global access point, making it unsuitable for the problem described. C) Observer Pattern : The Observer Pattern defines a one-to-many dependency between objects, where changes in one object are automatically reflected in dependent objects. It is ideal for event-driven systems but does not restrict the number of instances or provide global access, making it incorrect. D) Strategy Pattern : The Strategy Pattern allows behavior to be selected at runtime by encapsulating algorithms in separate classes. While it promotes flexibility, it does not deal with instance control or global access, making it irrelevant to the Singleton problem. E) Prototype Pattern : The Prototype Pattern involves creating new objects by copying existing ones rather than instantiating new ones. It is useful for object duplication but does not restrict the number of instances, hence it is not applicable here.
Select the most appropriate option to substitute the underlined segment in the given sentence. If there is no need to substitute it, select āNo substi...
Select the most appropriate word for the given group of words.
Branch of science that studies structure, classification and genetics of plants
Select the most appropriate synonym of the given word.
SUBSEQUENT
Select the most appropriate meaning of the given idiom.Ā
One track mind
Dealers cannot __________ profit due to increase in excise duty, and they should not be ___________ with loss due to reduction.
He got a job in the Railways through the back door.
Select the most appropriate option the can substituteĀ the bold segment in the given sentence.
She has let herself be gone after her divorce.Ā <...
The importers had ___________ that the IGST was being ____________ on them twice on the very same transaction by segregating portions of it.
Select the most appropriate word for the given group of words.
a slowly moving mass or river of ice
Select the most appropriate antonym of the given word.
EXACERBATE