Design Patterns Flashcards

1
Q

What are the three categories of design patterns (from Gang of Four)?

A

Creational
Structural
Behavioral

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

Role of Creational Design Patterns?

A

Abstract the instantiation

Make system independent of how objects are created, composed and represented

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

Role of Structural Design Patterns?

A

Compose classes/objects to form larger structures

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

Role of Behavioral Design Patterns?

A

Algorithms

Assignment of responsibilities between objects

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

What problems do the Observer Design Pattern seek to solve?

A

Maintaining consistency between related objects
Resolving dependency between two aspects
Want to notify other objects without making assumptions about the target objects.

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

Give a high level description of an Observer Design Pattern.

A

Two separate objects: Observable and Observer
Observable maintains a list of observers for itself
Detects changes and notifies all subscribed observers.

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

What is a Singleton Design Pattern?

A

A class which may only ever have a single instance that is globally accessible

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

Give a high level description of how a Singleton Design Pattern works.

A

Globally accessible getInstance() function that returns the singleton, or creates one if it does not exist

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

What is the purpose of an Iterator function?

A

Iterate over a container/collection of objects without revealing how elements are stored

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

What problems does the Strategy Design Pattern solve?

A

Want to use multiple different algorithms (strategies) at different times while minimizing amount of code that needs to be rewritten

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

Role of Creational Design Patterns?

A
  • Abstract the instantiation

- Make system independent of how objects are created, composed and represented

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

Role of Behavioral Design Patterns?

A
  • Algorithms

- Assignment of responsibilities between objects

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

What problems do the Observer Design Pattern seek to solve?

A
  • Maintaining consistency between related objects
  • Resolving dependency between two aspects
  • Want to notify other objects without making assumptions about the target objects.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give a high level description of an Observer Design Pattern.

A
  • Two separate objects: Observable and Observer
  • Observable maintains a list of observers for itself
  • Detects changes and notifies all subscribed observers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What problems does the Strategy Design Pattern solve?

A

Want to use multiple different algorithms (strategies) at different times while minimizing amount of code that needs to be rewritten

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

Give a high level description of how a Strategy Design Pattern works.

A
  • Implement multiple classes that differ only in behavior (algorithm version)
  • Works as implementation of algorithm is separate from implementation of class
17
Q

Type and description of MEMENTO

A
  • Behavioral

- Without violating encapsulation, backup internal state such that it can be restored to later.

18
Q

Type and description of CHAIN OF RESPONSIBILITY

A
  • Behavioral

- Chain request handlers together passing a request up until it is dealt with

19
Q

Type and description of OBSERVER

A
  • Behavioral

- One-to-many dependency between objects that notifies one object if the others’ state changes

20
Q

Type and description of COMMAND

A
  • Behavioral

- Encapsulating request as an object to allow parameterization of clients with different requests, etc.

21
Q

Type and description of STATE

A
  • Behavioral

- Allow an object to alter behavior if internal state changes

22
Q

Type and description of INTERPRETER

A
  • Behavioral

- Given a language, define the representation for grammar, along with interpreter

23
Q

Type and description of STRATEGY

A
  • Behavioral

- Define encapsulated family of algorithms and make them interchangeable

24
Q

Type and description of ITERATOR

A
  • Behavioral

- Access elements sequentially without exposing its underlying representation

25
Q

Type and description TEMPLATE METHOD

A
  • Behavioral

- Define algorithm as skeleton deferring to several subclasses allowing for easy redefinition without changing structure

26
Q

Type and description of MEDIATOR

A
  • Behavioral
  • Define an object that encapsulates how a set of objects interact. Prevents them from referring to each other explicitly
27
Q

Type and description of VISITOR

A
  • Behavioral

- Represent an operation to be performed on the elements of an object structure

28
Q

Type and description of ADAPTER

A
  • Structural

- Convert interface of a class into another interface clients expect

29
Q

Type and description of PROXY

A
  • Structural

- Provide placeholder for another object to control access to it

30
Q

Type and description of BRIDGE

A
  • Structural

- Decouple abstraction from implementation so that the two can vary independently

31
Q

Type and description of ABSTRACT FACTORY

A
  • Creational

- Interface used for creating families of related/dependent objects

32
Q

Type and description of COMPOSITE

A
  • Structural

- Arrange objects into tree structures. Allows users to interact with objects and their composite (children) uniformly

33
Q

Type and description of BUILDER

A
  • Creational
  • Separate the construction of a complex object from its representation such that the constructor can create multiple different representations
34
Q

Type and description of DECORATOR

A
  • Structural

- Attach additional responsibilities to an object. Flexible alternative to sub-classing.

35
Q

Type and description of FACTORY METHOD

A
  • Creational

- Interface for creating object but which classes to instantiate is dependent on subclasses.

36
Q

Type and description of FACADE

A
  • Structural

- Provide a high level interface for several interfaces of a subsystem

37
Q

Type and description of PROTOTYPE

A
  • Creational

- Use prototype to specify object desired to be created.

38
Q

Type and description of FLYWEIGHT

A
  • Structural

- Use sharing to support many different objectss efficiiently

39
Q

Type and description of SINGLETON

A
  • Creational

- Ensure class only has one instance and a global point of access.