Which design pattern is used to ensure a class has only one instance and provides a global point of access to it?
- Factory
- Observer
- Singleton
- Strategy
The design pattern used to ensure a class has only one instance and provides a global point of access to it is the Singleton pattern. This pattern restricts instantiation of a class to a single object and provides a way to access that instance globally. It is commonly used in scenarios such as database connections, logging mechanisms, and configuration settings where having multiple instances can lead to issues like resource wastage or inconsistent behavior.
Loading...
Related Quiz
- In a relational database, a _________ ensures that each row in a table is uniquely identifiable.
- To eliminate transitive dependency, a relation must be in at least ___________ Normal Form (NF).
- In a priority queue, elements are dequeued based on their ___________.
- Your Agile team is struggling to meet sprint goals due to frequent interruptions. How would you address this issue while maintaining Agile principles?
- How does a breadth-first search (BFS) differ from a depth-first search (DFS) in terms of traversal order in graphs?