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.
Two trains βAβ and βBβ started from station βPβ and βQβ towards station βQβ and βPβ respectively at the same time. When they met...
A train can cross a pole, a bridge of 600 meter long and platform of 480 meter long in 14 seconds, _____ seconds and 30 seconds, respectively.
Th...
Two trains, each 130 meters long, are running in opposite directions. If the speed of one train is twice that of the other and they take 13 seconds to c...
A train is moving at a constant speed of 234 km/hr. It takes 8 seconds to pass a pole and 18 seconds to cross a platform. Calculate the difference betw...
Without stopping the speed of the train is 120 kmph, with stopping the speed of the train is 70 kmph.Find the stop time of the train?
A train started from station P and preceded towards station Q at a speed of 90 km/h. 42 minutes later, another train started from station Q and preceded...
Two trains 200 metres and 100 metres in length are running towards each other on parallel tracks, one at the rate 50 km/hr and another at 40 km/hr. In h...
A train travels 240 km at a uniform speed. If the speed of the train is increased by 20 km/h, it takes 1 hour less to cover the same distance. What is t...
A train 300 metre long takes 20 sec to cross a man running at a speed of 6 km/hr in the direction same to that of train. What is the speed of the train?
Ratio of the lengths of two trains βXβ and βYβ is 6:7 respectively and the ratio of time taken by them to cross a pole is 2:3 respectively. If s...