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.
The least number which when divided by 6, 7, 10, 13, and 15 leaves the same remainder 5 in each case, is:
What is the Highest Common Factor of 54, 162 and 270?
HCF of two numbers 60 and 100 can be expressed in the form of (20m β 120) whereas LCM of these two numbers can be expressed in the form of (40n β 20...
Two men started moving in a circular path from the same place at the same time in the same direction. If they complete one revolution in 12 min and 16 m...
Two numbers are in the ratio 5:12, and their least common multiple (LCM) is 1,440. Determine the sum of these two numbers.
The LCM of two natural numbers is 10 times their HCF. If the product of given two numbers is 1000, then find the LCM of the numbers.Β
Find the greatest number of 4 digits divisible by 15, 25, 40 and 75.
The HCF of two numbers is 18 and their LCM is 540. If one of the numbers is 90, find the other number.
The HCF of two numbers is 9 and their LCM is 360. If one number is 45, find the other number.