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 average of 36 numbers is 75. If every number is multiplied by 9, what will be the average of the resulting numbers?
The average age of 4 children in a family is 30% of the average age of the mother and the youngest child. The total age of the father and the eldest chi...
A set contains ten numbers. The average of the first six numbers is (x - 4), and the average of the last three numbers is (x + 2). The average of the en...
The average of five even numbers is 68. If we replace two of these even numbers, 84 and 92, with a single even number X, the new average decreases by 4....
The average age of A, B & C is 48 years. Ratio of present ages of A to C is 3:5 and present age of B is 33.33% more than that of A. find the difference...
The average marks of 'm' students in a math test is (m + 5) and the average marks of 30 girls is (2m - 10). If the average marks of all students togethe...
The cost of running a mini train is partly fixed and partly variable. When 50 tickets are sold, the average cost per ticket is Rs. 45. When 70 tickets a...
In a class of 50 students, the girls are 76%. The average weight of boys is 62 kg and that of girls is 58 kg. What is the average weight (in kg) of whol...
Determine the average marks achieved by six additional aspirants if the average score of 24 aspirants in a mock test is 67. Adding the marks of these si...
The average of six numbers is 8. When three new numbers are included in such a way that the first number is  twice the second and second number is thri...