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 is the value of (4ab+ab2)/(a2 b),  a,b ≠0
I. a + b = 0
II. a – b = 1
- What is the smallest number of the six numbers? Â Statement I: Â The average of six consecutive odd numbers is 8. Â Statement II: Â The sum of six consec...
What is the smallest number of the six numbers? Â
I.The average of six consecutive odd numbers is 8. Â
II. The sum of six consecutive od...
The cost price of an article is Rs. 600. How much profit did a trader get by selling the article, if it was sold at 15% discount?
I. The trader ...
If 5p + 2q = 23, then determine the value of ‘p’
Statement I: 35p + 14q = 161
Statement II: 20p + 8q = 92
Each question is followed by three statements I, II and III. You have to decide whether the data given in the statements are sufficient to answer the qu...
Each question is followed by three statements I, II and III. You have to decide whether the data given in the statements are sufficient to answer the qu...
How many boys are there in the class?
I. The number of girls is 30% of the number of boys.
II. The ratio of the number of boys to that of girls is 3:5.
Is 'x' an even number?
Statement I: 'x' is not divisible by 8.
Statement II: When 1 is added to three times 'x', ...
A shopkeeper sells a homogeneous mixture of A and B at a rate of Rs 320 per kg. Find the profit percentage of the shopkeeper.
Statement I : he b...