Seminar 2 Flashcards
What is the Mediator pattern?
Defines an object that encapsulates how a set of objects interact/communicate. Instead of having each component refer to and communicate directly with the others (which creates tight coupling), the components communicate through a Mediator object.
Is the Mediator pattern behavioral, structural, or creational?
Behavioral.
When should you use the Mediator pattern?
When a system has complex interactions between multiple components.
What are the benefits of the Mediator pattern?
Reduces coupling, improves readability, centralizes communication.
What are the drawbacks of the Mediator pattern?
Can become a ‘god object’ and introduce performance overhead.
What is the Composite pattern?
A structural pattern that allows composing objects into tree structures.
* You define a common interface (e.g., Component) for both simple and complex elements.
- Leaf: A basic element (e.g., a file).
- Composite: A container that holds leaf or other composite elements (e.g., a folder).
- Each composite can contain children and delegates operations to them.
What are the benefits of the Composite pattern?
Simplifies client code, encourages polymorphism, improves scalability.
What are the drawbacks of the Composite pattern?
Can overly generalize the system and complicate debugging.
When should you use the Composite pattern?
When you want to treat individual objects and compositions the same way.
What are the key roles in the Composite pattern?
Component, Leaf, Composite.
What is the Iterator pattern?
A behavioral pattern for traversing elements without exposing their representation.
What are the benefits of the Iterator pattern?
Decouples traversal logic, supports multiple iteration styles.
What are the drawbacks of the Iterator pattern?
Adds extra classes and can be inefficient for simple collections.
When should you use the Iterator pattern?
When direct access is inefficient or multiple iteration styles are needed.
What are the key roles in the Iterator pattern?
Iterator, ConcreteIterator, Aggregate, ConcreteAggregate.
What is the Object Pool pattern?
Reuses expensive-to-create objects by managing them in a pool.
What are the benefits of the Object Pool pattern?
Improves performance, reduces memory use, manages heavy resources.
What are the drawbacks of the Object Pool pattern?
Requires object reset, is hard to manage with threads, unsuitable for light objects.
When should you use the Object Pool pattern?
When object creation is expensive or many similar objects are needed.
What are the key roles in the Object Pool pattern?
ObjectPool, Reusable, Client.