Which principle of object-oriented design does the Decorator Pattern promote most effectively?
Open/Closed Principle
Liskov Substitution Principle
Dependency Inversion Principle
Single Responsibility Principle
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.
Simple Factory promotes extensibility, while Factory Method is less flexible.
Simple Factory is better suited for complex object creation hierarchies.
Factory Method uses inheritance, while Simple Factory relies on a single factory class.
In the context of the Decorator Pattern, what is the relationship between the 'ConcreteComponent' and 'Decorator'?
Both the Decorator and ConcreteComponent implement the same interface.
The ConcreteComponent inherits from the Decorator.
The Decorator inherits from the ConcreteComponent.
There is no direct relationship between them.
When might the Strategy Pattern introduce unnecessary complexity?
When the algorithms are very similar and could be easily combined into a single class.
When the context needs to be aware of the concrete strategy being used.
When performance is absolutely critical, and the overhead of strategy objects is a concern.
When you have a small number of algorithms that are unlikely to change.
How does the Strategy Pattern promote the Open/Closed Principle?
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.
It promotes code reuse by allowing strategies to be shared across multiple contexts.
In which scenario would the Factory Method pattern be a more suitable choice than the Simple Factory pattern?
When you want to avoid using inheritance in your object creation process.
When object creation logic is simple and doesn't require subclass-specific variations.
When you anticipate the introduction of new product types in the future.
When you have a fixed set of objects to create and no need for future extensions.
Which of these is a common real-world analogy used to explain the Decorator Pattern?
Adding toppings to a base coffee or ice cream.
A tree structure representing hierarchical relationships.
A chain of objects processing a request sequentially.
A factory producing different types of objects.
What is a key benefit of encapsulating a request as an object in the Command Pattern?
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.
It prevents the use of undo/redo functionality.
What is the primary intent of the Command Pattern?
To encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests.
To define a family of algorithms, encapsulate each one, and make them interchangeable.
To ensure a class has only one instance, and provide a global point of access to it.
To provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
In Java, what keyword is commonly used to ensure thread-safe Singleton instantiation?
abstract
volatile
final
synchronized