Which of these relationships best describes the Composite pattern?
Association
Both Inheritance and Composition
Realization
Inheritance
What is the primary goal of the Flyweight pattern?
To define a family of algorithms, encapsulate each one, and make them interchangeable.
To provide a way to access shared objects in a synchronized manner.
To encapsulate algorithms in objects, allowing for easy swapping and extension.
To minimize memory usage by sharing common data among multiple objects.
How does the State Pattern typically handle state transitions?
The 'Context' object directly modifies its internal state.
State objects have methods to trigger transitions to other states.
A separate 'State Manager' class controls all transitions.
State transitions are determined by external events only.
Which of these scenarios best exemplifies the use of the Prototype Pattern?
Managing the state of a traffic light system.
Implementing undo/redo functionality in a text editor.
Creating multiple instances of game characters with slightly varying attributes.
Logging user actions in a system.
What is a potential drawback or consideration when using the Iterator Pattern?
It violates the Single Responsibility Principle.
Increased code complexity in some cases.
It leads to tight coupling between classes.
It is not suitable for all types of collections.
Which of these is NOT a potential benefit of using the Composite pattern?
Increased code complexity.
Open/Closed Principle adherence.
Uniform treatment of objects.
Flexibility in object structure.
How does the Flyweight pattern contribute to object-oriented design principles?
It promotes loose coupling by separating object creation from usage.
It enhances code reusability by encapsulating common behavior in shared objects.
All of the above.
It improves performance by reducing the number of objects instantiated.
How does a Virtual Proxy primarily enhance performance?
By storing copies of frequently accessed data to avoid repeated retrieval.
By restricting access to the real subject based on user permissions.
By providing a simplified representation of a complex object structure.
By delaying the creation of expensive objects until they are actually needed.
In the Builder Pattern, what is the role of the 'Director'?
It defines the abstract steps for building the object.
It represents the complex object being built.
It constructs the actual object using the Builder.
It provides an interface to access the built object.
How does the Iterator Pattern handle situations where the underlying collection might be modified during iteration?
It generally does not handle this directly; safeguards like concurrent modification exceptions might be needed.
It relies on the client code to manage synchronization and prevent issues.
It automatically prevents any modifications to the collection while iteration is in progress.
It creates a copy of the collection to ensure data integrity during iteration.