Which of the following is a key difference between the Factory Method and Simple Factory patterns?
Factory Method handles object creation centrally, whereas Simple Factory distributes it.
Factory Method uses inheritance, while Simple Factory relies on a single factory class.
Simple Factory is better suited for complex object creation hierarchies.
Simple Factory promotes extensibility, while Factory Method is less flexible.
Which of these is a common real-world analogy used to explain the Decorator Pattern?
A tree structure representing hierarchical relationships.
A chain of objects processing a request sequentially.
Adding toppings to a base coffee or ice cream.
A factory producing different types of objects.
Which of these scenarios best illustrates the use of a Facade Pattern?
Defining a one-to-many dependency between objects.
Creating multiple subclasses with specialized methods.
Providing a single, unified API to interact with a database system.
Iterating through a collection of objects without exposing its structure.
How does the Command Pattern achieve decoupling?
By relying on a central registry to map requests to their handlers.
By directly connecting the object making the request with the object fulfilling it.
By introducing an intermediary object (the Command) between the invoker and the receiver.
By using inheritance to create specialized request handlers.
How does the Decorator Pattern differ from traditional inheritance for extending functionality?
Decorator modifies the original class, while inheritance creates new subclasses.
Decorator provides more flexibility by allowing the combination of multiple functionalities at runtime.
Inheritance is generally preferred over Decorator due to its simplicity.
Inheritance allows for dynamic extension at runtime, while Decorator does not.
What is a key characteristic of a well-implemented design pattern?
It eliminates the need for documentation.
It introduces significant code complexity.
It is tightly coupled to a specific problem domain.
It promotes code reusability and maintainability.
What is a key benefit of encapsulating a request as an object in the Command Pattern?
It prevents the use of undo/redo functionality.
It allows for requests to be queued, logged, or supported by other operations.
It increases code coupling for better maintainability.
It makes the code more difficult to extend with new commands.
How does the Strategy Pattern promote the Open/Closed Principle?
It promotes code reuse by allowing strategies to be shared across multiple contexts.
It allows adding new strategies without modifying the existing Context class.
It reduces the need for inheritance, making the codebase more flexible.
It prevents modification of existing strategies, ensuring their integrity.
In a scenario where you are designing a game with different enemy types, how might the Factory Method pattern be applied?
Create a single factory class responsible for instantiating all enemy types based on given parameters.
Use a dependency injection framework to inject concrete enemy instances into the game logic.
Define an abstract 'EnemyFactory' with a 'createEnemy' method, and have subclasses for each enemy type implement their creation logic.
Hardcode the instantiation of each enemy type directly within the game logic where needed.
What is a potential downside of overusing design patterns?
Improved code performance
Reduced code complexity
Increased code readability
Unnecessary complexity and abstraction