Question
Which of the following design patterns is primarily used
to create objects without specifying the exact class of object that will be created?Solution
The Factory Method design pattern is a creational pattern used to create objects without having to specify the exact class of object that will be instantiated. Instead of calling a constructor directly, the client uses a factory method to create an object. This pattern promotes loose coupling by allowing the code that uses the objects to depend on interfaces rather than concrete classes. The Factory Method provides a way to delegate the responsibility of instantiation to subclasses, which can decide which class to instantiate based on specific criteria or conditions. Option A (Singleton) is incorrect because the Singleton pattern restricts instantiation to a single instance of a class, not multiple types of objects. Option C (Observer) focuses on the relationship between objects to notify observers of state changes, not object creation. Option D (Decorator) is a structural pattern that adds behavior to objects dynamically, rather than creating them. Option E (Strategy) defines a family of algorithms, encapsulating each one, but does not deal with object creation.
How many types of charts are there in LibreOffice?
Into how many parts is the MAC address divided?
Which protocol is lightweight?
Which protocol is related to e-commerce?
What is the purpose of 'encryption' in computer security?
What was the first graphical web browser?
Which bank launched a USSD application for its users?
Which of the following best describes a computer virus?
Which of the following is a strong password practice?
Where is the footer area displayed in the Headout Master?