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.
- A wristwatch was sold for Rs. 720.80, making a gain of 20%. If the selling price had been Rs. 690 instead, what would have been the profit or loss percenta...
- A shopkeeper bought a computer for Rs. 30,000 and a printer for Rs. 5,000. He sold the computer at a profit of 10% and the printer at a loss of 15%. Find t...
A chair listed at 550 is available at successive discounts of 25% and 10%. The selling price of the chair is
- An article has a cost price of Rs. 750 and is marked 40% above its cost price. 'A' proposes to sell this article after two successive discounts of 12% and ...
- A seller sold a product for Rs. 1152 after giving two identical discounts of x% each on the marked price of Rs. 1800. What is the value of x?
- The marked price of an article is 150 percent of its cost price. If 25% discount is given at the time of selling the article, then what will be the profit ...
Rahul sold a computer after giving a discount of 10% and earned a profit of Rs. 1200. If he had sold it for Rs. 300 less, he would have earned a profit ...
A shopkeeper marks the price of the article in such a way that after allowing 28% discount, he wants a gain of 12%. If the marked price is ₹224. then ...
Sara sold 30 scarves at a profit of 25%. If she had sold all the scarves for Rs. 3000 more, her overall profit would have been 50%. What is the selling ...
The purchasing price of 275 articles is equal to the selling price of 250 articles. Find the profit/loss%.