Which of these scenarios would be a suitable use case for the Decorator Pattern?
Implementing a logging system that can be added to different parts of an application.
Representing a family tree with complex relationships between members.
Managing the state of an object throughout its lifecycle.
Creating different types of vehicles with varying features.
Can you have multiple Facade classes for a single complex subsystem?
Yes, you can have different Facades exposing tailored functionalities.
Multiple Facades can only be used with abstract classes, not concrete ones.
No, the Facade Pattern restricts to only one Facade class.
It's possible but not recommended as it violates the pattern's principles.
Which of these is NOT a core component of the Strategy Pattern?
Strategy
Context
ConcreteStrategy
Factory
In the context of the Decorator Pattern, what is the relationship between the 'ConcreteComponent' and 'Decorator'?
There is no direct relationship between them.
The Decorator inherits from the ConcreteComponent.
The ConcreteComponent inherits from the Decorator.
Both the Decorator and ConcreteComponent implement the same interface.
How does the Decorator Pattern achieve the dynamic addition of responsibilities?
By modifying the source code of the decorated object at runtime.
By using reflection to alter the behavior of methods during execution.
By using inheritance to create subclasses with extended functionality.
By composing objects, where decorators wrap the component and delegate to it.
Which scenario best exemplifies a situation where the Command Pattern would be beneficial?
You have a simple algorithm that doesn't require encapsulation or extensibility.
You have a graphical user interface with buttons that trigger different actions on a document.
You need to represent a hierarchical relationship between objects.
You need to create objects of varying types based on user input.
What is the main difference between Object Adapter and Class Adapter?
Object Adapter uses inheritance, while Class Adapter uses composition.
Class Adapter uses inheritance, while Object Adapter uses composition.
There is no difference, both are implemented the same way.
Object Adapter is suitable for adapting concrete classes, while Class Adapter is for interfaces.
Which of these is NOT a benefit of using design patterns?
Improved code readability
Increased code duplication
Enhanced code maintainability
Facilitated code reuse
What potential issue could arise if an observer modifies the subject's state during notification?
It violates the principle of least astonishment.
It could result in unexpected behavior and make the system harder to reason about.
It could lead to an infinite loop.
All of the above
Which of these is a common real-world analogy used to explain the Decorator Pattern?
A chain of objects processing a request sequentially.
Adding toppings to a base coffee or ice cream.
A tree structure representing hierarchical relationships.
A factory producing different types of objects.