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.
Which state has launched the “Banglar Bari” scheme to provide houses for the rural poor?
Which Article of the Indian Constitution prohibits discrimination by the State on grounds of religion, race, caste, sex, or place of birth?
Which state received the highest Foreign Direct Investment (FDI) in Q1 FY 2024-25?
Kabaddi was introduced for the first time for promotional purposes as a demonstration sport in Olympic games in which year?
What is the purpose of the $200 million loan agreement between the Government of India and the Asian Development Bank (ADB) for Uttarakhand?
Which of the following airlines firm in India has selected Meta software 'Workplace' for intra-company communications?
Which financial institution is taking bold action to address methane emissions, launching at least 15 country-led programs in the next 18 months?
Who is the MD & CEO of Axis Bank ?
Consider the following statements about Middle-income trap:
I. Middle-income trap is a situation in middle-income countries where they are not ab...
Tansen, the famous musician, often sang in the court of which ruler?