Question
Which of the following design patterns violates the
Open/Closed Principle of SOLID principles in object-oriented design?ÂSolution
The Singleton pattern violates the Open/Closed Principle of SOLID, which states that software entities (classes, modules, functions) should be open for extension but closed for modification. The Singleton pattern is designed to restrict the instantiation of a class to a single object. To achieve this, the class is tightly coupled to its own instance management logic, which means modifying or extending this behavior requires changes to the original class. As a result, Singleton classes are not easily extensible without modification, making them contrary to the Open/Closed Principle. Why Other Options are Incorrect: A) Strategy Pattern: The Strategy Pattern adheres to the Open/Closed Principle by allowing algorithms to be selected and applied at runtime without modifying existing code. C) Factory Method Pattern: This pattern promotes extensibility by allowing subclasses to alter the type of objects that will be created, without modifying the client code. D) Decorator Pattern: The Decorator Pattern is designed to extend functionality dynamically by wrapping objects, adhering to the Open/Closed Principle. E) Adapter Pattern: The Adapter Pattern allows for existing classes to be used without modification by adapting their interfaces to a new target interface, following the Open/Closed Principle.
- What does DPI stand for in the context of printing resolution?
Which of the following statements is/are correct regarding the 16th Finance Commission (FC)?
1. It is established under Article 280 of the Indian...
- 'Atla Taddi' is a traditional festival celebrated in which Indian state?
- Which state government approved the Krishak Kalyan Mission in April 2025 to consolidate farmer welfare programs?
Match the following organizations with their headquarters:
Which is India’s oldest university, established in 1818?
By what year does India aim to eliminate malaria?
- Which Indian state became the first to establish a Senior Citizens Commission?
In commemoration of the birth anniversary of former Prime Minister Atal Bihari Vajpayee, Chief Minister Yogi Adityanath has inaugurated Uttar Pradesh's ...
Which operation was conducted by the Indian Navy to rescue an Iranian ship from pirates?