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.
Trade Union Act came into force in:
Are all industries subject to the provisions of the Industrial Disputes Act, 1947?
What is the minimum number of members required to apply for the registration of a trade union under Section 4 of the Trade Union Act, 1926?
Who was honored with France's highest civilian award, the "Chevalier de la Légion d'Honneur" (Knight of the Legion of Honour) in April 2023?
Which of the following financial ratios measures a company's efficiency in managing its inventory?
Which of the following uses spores to reproduce?
Which of the following statements are correct in regards to Gaganyaan Mission?
- India’s 1st human space mission to be l...
On which day is a major national festival celebrated every year to commemorate the enactment of the Constitution of India, which declared India to be a ...
According to recent report, which state recorded the highest total health expenditure in 2021-22?
In which organism sex is not determined genetically?