Test2_Chapter32 Flashcards

(17 cards)

1
Q

Iterator pattern

A

It allows traversal through a list or collection of data using a standard
interface without having to know the details of the internal representations of that data

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

Iterator interface

A

It declares the operations required for traversing a collection

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

Concrete iterators

A

They implement specific algorithms for traversing a collection

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

Collection interface

A

It declares one or multiple methods for getting iterators compatible with the collection

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

Concrete collections

A

They return new instances of a particular concrete iterator class

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

Client for the iterator pattern

A

It works with both collections and iterators via their interfaces

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

When to use the iterator pattern

A
  • When your collection has a complex data structure under the hood, but you want to hide its complexity from clients
  • Use the pattern to reduce duplication of the traversal code across your app.
  • Use the Iterator when you want your code to be able to traverse different data structures or when types of these structures are unknown beforehand
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Mediator pattern

A

It is a mechanism for facilitating communication between components

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

Concrete Mediators

A

They keep references to all components they manage

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

Mediator interface

A

It declares methods of communication with components, which usually include just a single Notify or Send method.

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

Components

A

They are one or more classes that contain some business logic

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

When to use the mediator pattern

A
  • Use the Mediator pattern when it is not desirable that instances of a class are aware of each other’s presence or communicate through references
  • Use the Mediator pattern when it is hard to change some of the classes because they are tightly coupled to a bunch of other classes.
  • Use the pattern when you cannot reuse a component in a different program because it is too dependent on other components.
  • Use the Mediator when you find yourself creating tons of component subclasses just to
    reuse some basic behaviour in various contexts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Memento pattern

A

It allows saving and restoring the previous state of an object without
revealing the details of its implementation

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

When to use the memento pattern

A
  • Use the Memento pattern when you want to produce snapshots of the object’s state to be able to restore a previous state of the object.

The Memento pattern lets you make full copies of an object’s state, including private fields, and store them separately from the object.

  • Use the pattern when direct access to the object’s fields/getters/ setters violates its encapsulation.

The Memento makes the object itself responsible for creating a snapshot of its state

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

Originator class

A

It can produce snapshots of its own state as well as restore its state from snapshots when needed

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

A caretaker

A

It keeps track of the originator’s history by storing a stack of mementos

17
Q

The memento

A

It is a value object that acts as a snapshot of the originator’s state.