Design Patterns Flashcards

1
Q

Is “separate the parts of the code that changes from what stays the same” a design principle?

A

Yes

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

Is “Program to an interface, not an implementation” a design principle?

A

Yes. Could be also program to a super type which can be replaced by something else

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

Is “Favor composition over inheritance” a design principle? Why?

A

Composition makes it easier to swap behavior. Inheritance is good to avoid code dup but maintenance is shitty

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

Is Strategy Pattern a design pattern? What does it say?

A

Yes. It defines a family of Algorithms, encapsulates them and makes them interchangeable.

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

What else does design patterns offer other than better maintenability?

A

Gives a shared vocabulary among developers. Patterns allow you to say more with less.

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

What does the observer pattern do?

A

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

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

What does the Decorator pattern do?

A

Wraps alike classes one on top of the other to compound results. Example sum the cost of add-ons of the milkshake

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

What does the The Factory Method Pattern do?

A

defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Example: build new customer() passed as argument to a class.

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

What does The Dependency Inversion Principle say? Is it OO?

A

Depend upon abstractions. Do not depend upon concrete classes. Yes

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

What does the command Pattern say?

A

The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.

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

What does the adapter pattern say?

A

The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

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

What does the facade pattern do?

A

The Facade Pattern provides a unifi ed interface to a set of interfaces in a subsytem. Facade defi nes a higherlevel interface that makes the subsystem easier to use.

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

What’s the Template Method Pattern?

A

The Template Method Pattern defi nes the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefi ne certain steps of an algorithm without changing the algorithm’s structure.

Example: OnCalculate ()

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

What is the Hollywood principle and what design pattern implements it?

A

The Hollywood Principle Don’t call us, we’ll call you. The template Method Pattern

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

What does the iterator pattern do?

A

The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

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

What’s the single responsability principle say?

A

A class should have only one reason to change.

17
Q

What is the composition pattern?

A

The Composite Pattern allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Example: tree of objects

18
Q

What does the state pattern say?

A

The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

19
Q

What is the chain of responsibility design pattern?

A

Chain of Responsibility is behavioral design pattern that allows passing request along the chain of potential handlers until one of them handles request. The pattern allows multiple objects to handle the request without coupling sender class to the concrete classes of the receivers.