Midterm2024 Flashcards

1
Q

What is the intent of the Flyweight pattern?

A

Use sharing to support large numbers of fine-grained objects efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What type of pattern classification is the Flyweight pattern?

A

Object Structural

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Flyweight?

A

A shared object that can be used in multiple contexts simultaneously

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What type of state is stored in the Flyweight?

A

Intrinsic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What type of state is stored with the Flyweight’s context?

A

Extrinsic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What 4 things must be true to use the Flyweight pattern?

A
  1. App uses a large number of objects making storage costs high
  2. Most object state can be made extrinsic
  3. Removing extrinsic state allows many groups of objects to be replaced by few shared objects
  4. The application doesn’t depend on object identity (identity tests will return true)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 5 participants of the Flyweight pattern?

A
  1. Flyweight
  2. ConcreteFlyweight
  3. UnsharedConcreteFlyweight
  4. FlyweightFactory
  5. Client
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What 2 issues need to be considered when implementing the Flyweight pattern?

A
  1. Removing extrinsic state
  2. Managing shared objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What type of pattern classification is the Strategy pattern?

A

Object Behavioural

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the intent of the Strategy pattern?

A

Define a family of algorithms and make them interchangeable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What else is the Strategy pattern known as?

A

Policy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 3 participants of the Strategy pattern?

A
  1. Strategy
  2. ConcreteStrategy
  3. Context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do the Context and the Strategy share data?

A

Context either passes all required data to the strategy or passes itself to the strategy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What participant does the Client interact with in a Strategy pattern?

A

After creating a ConcreteStrategy and passing it to the Context, Clients interact with Context exclusively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are 2 alternatives to using the Strategy pattern?

A
  1. Subclassing
  2. Conditional Statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of pattern classification is the Iterator pattern?

A

Object Behavioural

17
Q

What is the intent of the Iterator pattern?

A

Provide a way to access the elements of an aggregate object sequentially without exposing underlying representation

18
Q

What is another name for the Iterator pattern?

A

Cursor

19
Q

What is the key idea behind the Iterator pattern?

A

Take responsibility for access and traversal out of the list object and into an iterator object

20
Q

What are the 4 participants of the Iterator pattern?

A
  1. Iterator
  2. ConcreteIterator
  3. Aggregate
  4. ConcreteAggregate
21
Q

What is it called when a client controls the iteration?

A

External Iterator

22
Q

What is it called when the aggregate defines the traversal algorithm of an Iterator and uses the iterator to store state of iteration?

A

Cursor

23
Q

What type of pattern classification is the Prototype pattern?

A

Object Creational

24
Q

What is the intent of the Prototype pattern?

A

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype

25
Q

What are the 3 participants of the Prototype pattern?

A
  1. Prototype
  2. ConcretePrototype
  3. Client
26
Q

What are the 3 scenarios where the Prototype pattern should be used?

A
  1. Classes you need to instantiate are specified at run-time
  2. Want to avoid building a ton of factories
  3. Instances of a class only have a few different combinations of state
27
Q

What type of pattern classification is the Template pattern?

A

Class Behavioural

28
Q

What is the intent of the Template pattern?

A

Define the skeleton of an algorithm and deferring some steps to subclasses

29
Q

What is a template method?

A

Defines an algorithm in terms of abstract operations that subclasses override to provide concrete behaviour

30
Q

What are the 2 participants in the Template pattern?

A
  1. AbstractClass
  2. ConcreteClass
31
Q

What operations can optionally be overridden in the Template pattern?

A

Hooks

32
Q

Which operations must be overridden in the Template pattern?

A

Abstract

33
Q

The Template pattern is the Class Behavioural version of what other pattern?

A

Strategy

34
Q

What is meant by “the Hollywood principle”?

A

Inverted control structure where the parent class calls operations on the subclass.
“Don’t call us, we’ll call you”

35
Q

What pattern is considered a form of the Template method?

A

Factory Method

36
Q

What 2 criteria are patterns classified by?

A
  1. Purpose
  2. Scope
37
Q

What are the 3 purpose sub-categories for pattern classification?

A
  1. Creational
  2. Structural
  3. Behavioural
38
Q

What are the 2 scope sub-categories for pattern classification?

A
  1. Class
  2. Object