Design Patterns Flashcards

1
Q

Creational Patterns

A

Used to construct objects such that they can be decoupled from their implementing system.

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

Structural Patterns

A

Used to form large object structures between many disparate objects.

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

Behavioural Patterns

A

Used to manage algorithms,

relationships, and responsibilities between objects.

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

Object Scope

A

Deals with object relationships that can be

changed at runtime.

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

Class Scope

A
Deals with class relationships that can be changed
at compile time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Creational Patterns (5)

A
  • Abstract Factory
  • Builder
  • Factory Method
  • Prototype
  • Singleton
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Structural Patterns (7)

A
  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Behavioural Patterns (11)

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
9
Q

Chain of Responsibility Purpose

A

Gives more than one object an opportunity to handle a request
by linking receiving objects together.

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

Use Chain of Responsibility When

A
  • Multiple objects may handle a request and the handler
    doesn’t have to be a specific object.
  • A set of objects should be able to handle a request with the
    handler determined at runtime.
  • A request not being handled is an acceptable potential
    outcome.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Command Purpose

A

Encapsulates a request allowing it to be treated as an object.
This allows the request to be handled in traditionally object-based relationships such as queuing and callbacks.

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

Use Command When

A
  • You need callback functionality.
  • Requests need to be handled at variant times or in variant orders.
  • A history of requests is needed.
  • The invoker should be decoupled from the object handling the
    invocation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Interpreter Purpose

A

Defines a representation for a grammar as well as a mechanism
to understand and act upon the grammar.

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

Use Interpreter When

A
  • There is grammar to interpret that can be represented as
    large syntax trees.
  • The grammar is simple.
  • Efficiency is not important.
  • Decoupling grammar from underlying expressions is desired.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Iterator Purpose

A

Allows for access to the elements of an aggregate object

without allowing access to its underlying representation.

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

Use Iterator When

A
  • Access to elements is needed without access to the entire
    representation.
  • Multiple or concurrent traversals of the elements are needed.
  • A uniform interface for traversal is needed.
  • Subtle differences exist between the implementation details
    of various iterators.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Mediator Purpose

A

Allows loose coupling by encapsulating the way disparate sets of
objects interact and communicate with each other. Allows for the
actions of each object set to vary independently of one another.

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

Use Mediator When

A
  • Communication between sets of objects is well defined
    and complex.
  • Too many relationships exist and common point of control
    or communication is needed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Memento Purpose

A

Allows for capturing and externalizing an object’s internal
state so that it can be restored later, all without violating
encapsulation.

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

Use Memento When

A
  • The internal state of an object must be saved and restored
  • Internal state cannot be exposed by interfaces without exposing
    implementation.
  • Encapsulation boundaries must be preserved.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Observer Purpose

A

Lets one or more objects be notified of state changes in other
objects within the system.

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

Use Observer When

A
  • State changes in one or more objects should trigger behaviour
    in other objects
  • Broadcasting capabilities are required.
  • An understanding exists that objects will be blind to the expense of notification.
23
Q

State Purpose

A

Ties object circumstances to its behaviour, allowing the object
to behave in different ways based upon its internal state.

24
Q

Use State When

A
  • The behaviour of an object should be influenced by its state
  • Complex conditions tie object behaviour to its state.
  • Transitions between states need to be explicit.
25
Q

Strategy Purpose

A

Defines a set of encapsulated algorithms that can be swapped

to carry out a specific behaviour.

26
Q

Use Strategy When

A
  • The only difference between many related classes is their behaviour.
  • Multiple versions or variations of an algorithm are required.
  • Algorithms access or utilize data that calling code shouldn’t be exposed to.
  • The behaviour of a class should be defined at runtime.
  • Conditional statements are complex and hard to maintain.
27
Q

Template Method Purpose

A

Identifies the framework of an algorithm, allowing implementing
classes to define the actual behaviour.

28
Q

Use Template Method When

A
  • A single abstract implementation of an algorithm is needed.
  • Common behaviour among subclasses should be localized to a
    common class.
  • Parent classes should be able to uniformly invoke behaviour in their subclasses.
  • Most or all subclasses need to implement the behavior.
29
Q

Visitor Purpose

A

Allows for one or more operations to be applied to a set of objects
at runtime, decoupling the operations from the object structure.

30
Q

Use Visitor When

A
  • An object structure must have many unrelated operations performed upon it.
  • The object structure can’t change but operations performed on it can.
  • Operations must be performed on the concrete classes of an object structure.
  • Exposing the internal state or operations of the object structure is acceptable.
  • Operations should be able to operate on multiple object
    structures that implement the same interface sets.
31
Q

Adapter Purpose

A

Permits classes with disparate interfaces to work together by
creating a common object by which they may communicate
and interact.

32
Q

Use Adapter When

A
  • A class to be used doesn’t meet interface requirements.
  • Complex conditions tie object behaviour to its state.
  • Transitions between states need to be explicit.
33
Q

Bridge Purpose

A

Defines an abstract object structure independently of the

implementation object structure in order to limit coupling.

34
Q

Use Bridge When

A
  • Abstractions and implementations should not be bound at
    compile time.
  • Abstractions and implementations should be independently
    extensible.
  • Changes in the implementation of an abstraction should
    have no impact on clients.
  • Implementation details should be hidden from the client.
35
Q

Composite Purpose

A

Facilitates the creation of object hierarchies where each object
can be treated independently or as a set of nested objects
through the same interface.

36
Q

Use Composite When

A
  • Hierarchical representations of objects are needed.

- Objects and compositions of objects should be treated uniformly.

37
Q

Decorator Purpose

A

Allows for the dynamic wrapping of objects in order to modify
their existing responsibilities and behaviors.

38
Q

Use Decorator When

A
  • Object responsibilities and behaviours should be dynamically
    modifiable.
  • Concrete implementations should be decoupled from
    responsibilities and behaviours.
  • Subclassing to achieve modification is impractical or impossible.
  • Specific functionality should not reside high in the object hierarchy.
  • A lot of little objects surrounding a concrete implementation is
    acceptable
39
Q

Facade Purpose

A

Supplies a single interface to a set of interfaces within a system.

40
Q

Use Facade When

A
  • A simple interface is needed to provide access to a complex system.
  • There are many dependencies between system implementations
    and clients.
  • Systems and subsystems should be layered.
41
Q

Flyweight Purpose

A

Facilitates the reuse of many fine grained objects, making the
utilization of large numbers of objects more efficient.

42
Q

Use Flyweight When

A
  • Many like objects are used and storage cost is high.
  • The majority of each object’s state can be made extrinsic.
  • A few shared objects can replace many unshared ones.
  • The identity of each object does not matter.
43
Q

Proxy Purpose

A

Allows for object level access control by acting as a pass through
entity or a placeholder object.

44
Q

Use Proxy When

A
  • The object being represented is external to the system.
  • Objects need to be created on-demand.
  • Access control for the original object is required.
  • Added functionality is required when an object is accessed.
45
Q

Abstract Factory Purpose

A

Provide an interface that delegates creation calls to one or

more concrete classes in order to deliver specific objects.

46
Q

Use Abstract Factory When

A
  • The creation of objects should be independent of the system utilizing them.
  • Systems should be capable of using multiple families of objects.
  • Families of objects must be used together.
  • Libraries must be published without exposing implementation details.
  • Concrete classes should be decoupled from clients.
47
Q

Builder Purpose

A

Allows for the dynamic creation of objects based upon easily

interchangeable algorithms.

48
Q

Use Builder When

A
  • Object creation algorithms should be decoupled from the system.
  • Multiple representations of creation algorithms are required.
  • The addition of new creation functionality without changing
    the core code is necessary.
  • Runtime control over the creation process is required.
49
Q

Factory Method Purpose

A

Exposes a method for creating objects, allowing subclasses to
control the actual creation process.

50
Q

Use Factory Method When

A
  • A class will not know what classes it will be required to create.
  • Subclasses may specify what objects should be created.
  • Parent classes wish to defer creation to their subclasses.
51
Q

Prototype Purpose

A

Create objects based upon a template of an existing objects

through cloning.

52
Q

Use Prototype When

A
  • Composition, creation, and representation of objects should
    be decoupled from a system.
  • Classes to be created are specified at runtime.
  • A limited number of state combinations exist in an object.
  • Objects or object structures are required that are identical or closely resemble other existing objects or object structures.
  • The initial creation of each object is an expensive operation.
53
Q

Singleton Purpose

A

Ensures that only one instance of a class is allowed within a system.

54
Q

Use Singleton When

A
  • Exactly one instance of a class is required.

- Controlled access to a single object is necessary.