Behavior Design Patterns Flashcards
Name all the behavioral gof patterns
Chain of responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor
Give an example of the command pattern
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)
Give an example of the mediator pattern
An angular service. Shares data between different components.
Give an example of the chain of responsibility pattern. And how is it diff from / similar to pipeline?
Apigee handling requests. And pipeline has an organizing class
Give an example of the observer pattern
Pub/sub - rxjs.
Give an example of an interpreter pattern
Rhino.js -> JavaScript that compiles to java
Give an example of an iterator pattern
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
Give an example of the memento pattern
Something that can save state without breaking encapsulation. So a dB snapshot for example
Give an example of a visitor pattern
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)