Discussion
Which design pattern ensures a class has only one instance and provides a global point of access to it ?
Answer: B
The pattern is the Singleton Pattern.
A singleton makes its constructor private, keeps its single instance in a static field, and exposes it through a static method such as getInstance(). This ensures one instance and gives a global point of access to it, which is useful for things like a configuration object or a logger.
The Factory pattern creates objects without exposing the concrete class. Observer lets objects subscribe to another object's changes. Strategy swaps interchangeable algorithms at run time. None of them limits a class to one instance.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development