Which of the following design patterns is used to separate the construction of a complex object from its representation so that the same construction process can create different representations?
25 views
- Factory Method
- Builder (Correct Answer)
- Singleton
- Decorator
Explanation
Answer: b) Builder
Explanation:
The Builder design pattern is used to separate the construction of a complex object from its representation so that the same construction process can create different representations. The Factory Method design pattern is used to define an interface for creating objects, but lets subclasses decide which class to instantiate. The Singleton design pattern is used to ensure that a class has only one instance and provide a global point of access to it. The Decorator design pattern is used to attach additional responsibilities to an object dynamically.