Midterm2024 Flashcards
What is the intent of the Flyweight pattern?
Use sharing to support large numbers of fine-grained objects efficiently.
What type of pattern classification is the Flyweight pattern?
Object Structural
What is a Flyweight?
A shared object that can be used in multiple contexts simultaneously
What type of state is stored in the Flyweight?
Intrinsic
What type of state is stored with the Flyweight’s context?
Extrinsic
What 4 things must be true to use the Flyweight pattern?
- App uses a large number of objects making storage costs high
- Most object state can be made extrinsic
- Removing extrinsic state allows many groups of objects to be replaced by few shared objects
- The application doesn’t depend on object identity (identity tests will return true)
What are the 5 participants of the Flyweight pattern?
- Flyweight
- ConcreteFlyweight
- UnsharedConcreteFlyweight
- FlyweightFactory
- Client
What 2 issues need to be considered when implementing the Flyweight pattern?
- Removing extrinsic state
- Managing shared objects
What type of pattern classification is the Strategy pattern?
Object Behavioural
What is the intent of the Strategy pattern?
Define a family of algorithms and make them interchangeable.
What else is the Strategy pattern known as?
Policy
What are the 3 participants of the Strategy pattern?
- Strategy
- ConcreteStrategy
- Context
How do the Context and the Strategy share data?
Context either passes all required data to the strategy or passes itself to the strategy
What participant does the Client interact with in a Strategy pattern?
After creating a ConcreteStrategy and passing it to the Context, Clients interact with Context exclusively.
What are 2 alternatives to using the Strategy pattern?
- Subclassing
- Conditional Statements