WorksheetsUnderstanding Creational Design Patterns
Total questions: 8
Worksheet time: 4mins
What is the main purpose of the Singleton pattern?
To restrict instantiation of a class to a single instance.
To allow multiple instances of a class.
To provide a global access point to a class.
To enhance the performance of class instantiation.
Which design pattern allows for the creation of objects without specifying the exact class of the object?
Prototype Pattern
Factory Method
Builder Pattern
Singleton Pattern
In which scenario would you use the Builder pattern?
When implementing a factory for object creation.
When creating simple objects with fixed parameters.
When constructing complex objects with many optional parameters.
When managing state in a single-threaded environment.
How does the Abstract Factory pattern differ from the Factory Method pattern?
The Abstract Factory pattern is used for object pooling, whereas the Factory Method pattern is for object creation.
The Abstract Factory pattern creates a single object, while the Factory Method pattern creates families of related objects.
The Abstract Factory pattern creates families of related objects, whereas the Factory Method pattern creates a single object.
The Abstract Factory pattern focuses on object lifecycle, while the Factory Method pattern emphasizes object configuration.
What are the advantages of using the Factory pattern over direct instantiation?
Higher performance in object creation
The advantages of using the Factory pattern include flexibility, decoupling, easier management of object creation, support for polymorphism, simplified testing, and enhanced scalability.
Increased complexity in object management
Limited support for inheritance
Describe a real-world example where the Builder pattern would be beneficial.
A car assembly line.
A software installation process.
A clothing manufacturing workflow.
A meal order in a restaurant.
What are the potential downsides of using the Abstract Factory pattern?
Increased complexity, reduced flexibility, rigid structure, and potential unnecessary abstraction.
Easier testing, improved scalability, dynamic structure, and potential code duplication.
Simplified implementation, enhanced adaptability, flexible design, and reduced abstraction.
Lower performance, increased maintenance, simpler structure, and potential over-engineering.
In what scenario might you choose to use a Factory Method instead of an Abstract Factory?
Select a Factory Method when you require complex product configurations.
Use a Factory Method when you need to create multiple product types at once.
Choose an Abstract Factory for simple product creation without customization.
Use a Factory Method when you need to create a single product type with simple instantiation.
