Question
Which design pattern is best suited for managing the
creation of objects without specifying their concrete classes?Solution
The Factory Pattern is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created. It abstracts the instantiation process, enabling flexibility and scalability in object creation. For instance, in a GUI framework, the factory method might create different types of buttons (WindowsButton, MacButton) depending on the operating system. By decoupling the client code from concrete classes, this pattern promotes adherence to the Open/Closed Principle of SOLID. Why Other Options Are Incorrect :
- Singleton Pattern : This ensures a class has only one instance and provides global access to it, unrelated to flexible object creation.
- Observer Pattern : This defines a one-to-many dependency, where changes in one object are notified to multiple observers.
- Adapter Pattern : This works as a bridge between incompatible interfaces, not for object creation.
- Decorator Pattern : This adds functionality dynamically to objects, without modifying their structure.
The ratio of the speed of boat ‘A’ in still water, the speed of boat ‘B’ in still water and the speed of the current is 11:5:2, respectively. If...
A man row a boat 1 km in 5 min, along the stream and 6 km in 1hrs against the stream, The speed of the stream will beÂ
A boat can travel 12 km more in downstream than that in upstream, in 3 hours while the difference between the time taken by the same boat to travel 180 ...
A boat can cover 60 km in still water and 75 km in downstream in 4 hours and 3 hours respectively. Find the time taken by the boat to cover 60 km upstre...
"A boat covers 66 km upstream and 98 km downstream in a total of 9 hours. Determine the time required for the boat to travel 48 k...
A boat sails 150 km in downstream direction in 5 hours. If the upstream speed is one-third of its downstream speed, calculate the time it will take to c...
The speed of a boat in still water is 45 km/hr, and the speed of the stream is 5 km/hr. The boat takes 30 minutes longer to cover a distance of x km ups...
The time taken by a boat to travel a certain distance downstream is in the ratio 4:5 compared to the time taken to travel the sam...
Speed of a boat in still water is three times the speed of the boat in upstream. If the boat takes 40 minutes to cover 15 km in downstream, then find th...
A boat takes 34 hours to travel from P to Q upstream and from Q to P downstream. If the speed of the boat in still water is 8.5 km/h and the speed of th...