Design Patterns Flashcards

1
Q

What is a design pattern?

A

A design pattern is a way of reusing abstract knowledge about a problem and its solution. The pattern is a description of the problem and the essence of its solution.

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

(True or False) Design patterns should not be abstract. They need to be specific to be used in a variety of settings.

A

False! They actually need to be abstract to be applied in different settings.

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

What, in particular, are patterns?

A

Patterns (and pattern languages) are ways to describe bes praticies, good designes, and capture experience in a way that is possible for other to reuse this experience.

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

What are pattern elements?

A
  1. Name
  2. Problem description
  3. Solution description (not an actual design byt a template for a solution that can be instantiated in different ways)
  4. Consequences (the rults and trade-offs of applying the pattern.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Observer Pattern?

A

The Observer pattern is a behavioral design pattern that establishes a one-to-many relationship between a subject and its observers, allowing multiple observers to automatically receive updates when the subject’s state changes. It promotes loose coupling, enabling observers to react to changes without tightly binding them to the subject.

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

What is pub-sub?

A

Pub sub is a subscribing system. It can also bee seen as real-time updates from the source to the application. This pairs most with the observer pattern.

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

What are the design pattern classes?

A
  1. Creational design patterns (dealing with class instantiation and object creation, effective inheritance, object delegation)
  2. Structural design patterns (defines inheritance to compose interfaces, construction of objects to obtain new functionality)
  3. Behavioral Design Patterns (explores class and object communication, interaction between objects)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

(Creational Design Patterns) What is Abstract Factory?

A

Creates an instance of several families of classes.

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

(Creational Design Patterns) What is Builder?

A

Separates object construction from its representation.

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

(Creational Design Patterns) What is Factory Method?

A

Creates an instance of several derived classes

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

(Creational Design Patterns) What is Object Pool?

A

Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. (Library pre-creates instances of books for checkout)

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

(Creational Design Patterns) What is Prototype?

A

A fully initialized instance to be copied or cloned. This helps us to see what kind of edits we want. When we decide, we create a copy and then edit that.

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

(Creational Design Patterns) What is Singleton?

A

A class of which only a single instance can exist.

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

(Creational Design Patterns) What is Adapter?

A

Match interfaces of different classes. We make two things work together like an adapter. An adaptor creates an intermediary abstraction that translates, or maps, the old component to the new system.

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

(Creational Design Patterns) What is Decorator?

A

Add responsibilities to objects dynamically. (You add functionality to existing objects like scroll bars)

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

(Creational Design Patterns) What is Facade?

A

A single class that represents and entire subsystem. (Hides complexity and acts like a wrapper)

17
Q

(Creational Design Patterns) What is Proxy?

A

An object representing another object. (EX: a check is a proxy for the actual money. The bank checks the proxy and then puts the money in your account.)

18
Q

(Creational Design Patterns) What is Iterator?

A

Sequentially access the elements of a collection. (An example is a map program. Once you’ve hit this step, this is your next direction)

19
Q

(Creational Design Patterns) What is Memento?

A

Capture and restore an objects internal state. (There are two examples; Google Docs, and Google pages.

Google docs - Lockbox is the current state of the document and the caretakers are the editors.
Google pages - Google asking if you want to restore the pages when they suddenly closed.

20
Q

In what interface is proxy most commonly used?

A

In layered architecture. We can get the information we need without breaking the interface.

21
Q

What is the difference between adapter, proxy, and decrator?

A

Adapter provides a dofferent interface.
Proxy provides the same interface.
Decorator is more transparent to the client.