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.
Consider the following statements about the aim of PM GatiShakti Scheme:
(1)Â To have two new defence corridors.
(2)Â Extending 4G con...
What is the primary focus of the Dubai Gaming Visa introduced by the Crown Prince of Dubai?
According to the new UNAIDS report "The Urgency of Now: AIDS at a Crossroads," what is one of the critical steps needed to end the AIDS pandemic by 2030?
44th World Chess Olympiad 2022, which is to be hosted by India, earlier was to be hosted by?
________ is aiming to invest 165 billion rupees in clean energy projects to meet its 2040 net zero carbon emissions goal.
As part of the Centre’s infrastructure push, the Union Cabinet has approved seven proposals by the Ministry of Railways to expand the rail network in ...
Which of the following statements is true about the Jan Vishwas (Amendment of Provisions) Bill, 2023 recently passed in Lok Sabha?
Who has been selected as the new Chief Technologist of NASA?
The first service of the theme-based Bharat Gaurav Train started its journey from Coimbatore North to which place?
Which Indian state became the top producer and exporter of processed potatoes in 2024–25?Â