Patrones de Diseño Creacional Flashcards
(25 cards)
What is the main purpose of the Builder pattern?
To construct complex objects step by step.
True or False: The Singleton pattern allows multiple instances of a class.
False
Fill in the blank: The _______ pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Abstract Factory
What is a key characteristic of the Factory Method pattern?
It defines an interface for creating an object but allows subclasses to alter the type of objects that will be created.
What does the Prototype pattern do?
It creates new objects by copying an existing object, known as the prototype.
Which creational pattern ensures that a class has only one instance and provides a global point of access to it?
Singleton
Multiple Choice: Which of the following is NOT a creational pattern? A) Builder B) Observer C) Singleton D) Factory Method
B) Observer
Short Answer: What is the benefit of using the Builder pattern?
It allows for more control over the construction process and can create different representations of an object.
True or False: The Abstract Factory pattern can produce different types of objects that are related.
True
Fill in the blank: In the Factory Method pattern, subclasses are responsible for _______ the objects.
creating
What is the main advantage of the Prototype pattern?
It can be more efficient than creating new instances from scratch, especially for complex objects.
Short Answer: How does the Singleton pattern restrict instantiation?
It makes the constructor private and provides a static method to get the instance.
Multiple Choice: Which pattern is best suited for creating objects without specifying their concrete classes? A) Builder B) Singleton C) Abstract Factory D) Prototype
C) Abstract Factory
True or False: The Builder pattern can only be used with immutable objects.
False
Fill in the blank: The _______ pattern allows a class to delegate the responsibility of object creation to its subclasses.
Factory Method
What is one common use case for the Singleton pattern?
Managing shared resources like a configuration object or logging service.
Short Answer: What is a disadvantage of the Singleton pattern?
It can introduce global state into an application, which may lead to issues in testing and concurrency.
Multiple Choice: Which of the following patterns allows for changing the internal representation of an object? A) Builder B) Prototype C) Singleton D) Abstract Factory
A) Builder
True or False: The Factory Method pattern can only create one type of object.
False
Fill in the blank: The _______ pattern is useful when a system should be independent of how its products are created, composed, and represented.
Abstract Factory
What does the Builder pattern help to improve in terms of code quality?
Readability and maintainability.
Short Answer: In what scenario is the Prototype pattern particularly useful?
When creating objects that are expensive to create or require a lot of setup.
Multiple Choice: Which pattern is known for its use of a ‘clone’ method? A) Builder B) Singleton C) Prototype D) Factory Method
C) Prototype
True or False: The Builder pattern can only be used for creating complex objects.
False