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.
When a number is added to its multiple of 5 and its square, the sum of these three numbers is 91. Find the number.
Meeta correctly remembers that her father’s birthday is after 8th July but before 12th July. Her brother correctly remembers tha...
If 84 × 13 = 8, 37 × 13 = 6, 26 × 11 = 6, then 56 × 22 = ?
If + means ÷, - means x, x means +, ÷ means –, Find the value for 72 + 8 – 5 × 18 ÷ 5.