Behavior Design Patterns Flashcards

1
Q

Name all the behavioral gof patterns

A
Chain of responsibility
Command
Interpreter
Iterator 
Mediator
Memento
Observer
State
Strategy 
Template Method
Visitor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of the command pattern

A

Command center with servers in different regions that have many-step tasks. You could have commands for the servers as classes with an Invoker that invokes them. For example, “new RestartCommand(asiaServer)

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

Give an example of the mediator pattern

A

An angular service. Shares data between different components.

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

Give an example of the chain of responsibility pattern. And how is it diff from / similar to pipeline?

A

Apigee handling requests. And pipeline has an organizing class

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

Give an example of the observer pattern

A

Pub/sub - rxjs.

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

Give an example of an interpreter pattern

A

Rhino.js -> JavaScript that compiles to java

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

Give an example of an iterator pattern

A

Java iterator. Work with classes that implement iterator. So you can call .hasNext and .next without knowing the inner workings. This is how for : loops work under the hood

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

Give an example of the memento pattern

A

Something that can save state without breaking encapsulation. So a dB snapshot for example

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

Give an example of a visitor pattern

A

Something that uses a traverser to walk a structure and perform an operation- for example add new functionality to a bunch of diff classes (my css diffing tool)

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