chapter 4 Flashcards

(41 cards)

1
Q

define a design pattern.

A

pattern is a general repeatable solution to commonly occurring problem in OO software design [ context ].

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

is a design pattern a finished design? why?

A
  • its not a finished design that can be transformed into a code, but rather a template for how to solve a problem.
    Example:
  • house blueprint
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

the book; The Gang of Four’s book was written based on the principles of _____________ ?

A

Christopher Alexander

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

what did the GoF’s book achieve?

A

initiated the concept of design patterns in software dev’t

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

according to the GoF, a design pattern should be based on which OO principles?

A
  • program to an interface not an implementation
  • favor object composition over inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are types of DP defined by the GoF?

A
  • creational dp
  • structural dp
  • behavioral dp
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

describe creational dp

A
  • creates objs in a manner suitable for the situation.
  • deals with obj instantiation
  • hides creation logic, instead of just using the new operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

describe a structural dp?

A
  • deals with r/n ships b/n entities, to make it easier for them to work together
  • concerned with classes and object composition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

describe behavioral dp

A
  • concerned with common communication patterns b/n objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

a factory method is a pattern catalog belonging to ____________ dp?

A

creational

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

an adapter is a pattern catalog belonging to ____________ dp?

A

structural

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

what are characteristics of a dp?

A

LV R
- levels - decomposition of patterns
- view points - description of patterns
- roles - “players” in pattern usage

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

what is the d/ce b/n static and dynamic viewpoints?

A
  • static vp - describes class models [ building blocks ]
  • dynamic vp - seq diagrams
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what are the forms of a dp?

A

FDR
- delegation
- recursion

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

describe delegation dp form.

A
  • a mechanism in w/c an obj delegates a req to another obj
  • the other obj carries out the req on behalf of the original obj
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

describe recursion dp?

A
  • a mechanism in w/c part of the pattern uses itself
    Example:
  • GUIs where windows within windows are allowed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what are the goals of a dp?

A

GRE
- reuse of designs
- evolution of sw

18
Q

how can we achieve the goals of a dp?

A

by reducing dependencies among components
- program to interfaces not implementations
- favor obj composition not inheritance
- use delegation

19
Q

what are elements of a dp?

A

NPC are Sus
- name
- problem
- consequence
- solution

20
Q

____________ is an element of a dp, that describes when to apply a pattern?

21
Q

____________ is an element of a dp, that describes elements that make up the pattern, their r/n ship and responsibilities?

22
Q

____________ is an element of a dp, that describes results and the tradeoffs of applying the pattern?

23
Q

explain what scope is in a dp

A
  • describes what the pattern applies to
    Example:
  • class patterns : focus on r/n ships b/n classes and subclasses
  • obj patterns : focus on r/n ships b/n objs
24
Q

what scope of dp deals with class inheritance?

A

class pattern

25
what scope of dp deals with obj composition?
object pattern
26
explain how creational patterns provide flexibility?
- the pattern creates objs for us, instead of us instantiating objs - hence program has flexibility in deciding which objs need to be created
27
what is the intent of a simple factory pattern?
- abstracts logic of object creation [ simpleBurger Factory ] - refers to newly created obj through a common interface [ Burger burger ]
28
describe the adapter design pattern?
the example about xml and json - is a structural dp that allows incompatible interfaces to collaborate with one another
29
what is the intent of an adapter pattern?
- matches an existing object to a particular interface
30
compare and contrast b/n inheritance and composition.
Inheritance : aka white box - all subclasses are dependent [ tightly coupled ] with the parent class - unnecessarily complex - can easily break code upon change Composition : aka black box - one class can use another - loosely coupled - implementations can be easily replaced with out breaking code
31
give examples of types of behavioral dp.
- observer dp - memento dp
32
what is the observer pattern?
remember the store, owner and customer - is a behavioral dp that defines a 1-to-many r/n ship b/n objects [ subject and observer ] - so when a subject changes state, all observers are notifies and updated
33
what are examples of an observer dp?
- broadcasts - publish - subscribe
34
what are the key players in the observer pattern?
- subject / publisher [ list of sub, sub and unsub methods ] - object / subscriber - an updating interface for obj that get notified upon changes to a subject - concrete subject - concrete observer - implements update interface
35
describe the memento dp?
is a behavioral dp that delegates the task of creating the State of Snapshots to the actual owner of that state. - prevents other objects from trying to copy the state of the class from outside of the class
36
what is memento pattern used for?
- is used to restore the state of an object to a previous state Example: - Ctrl + Z in editors - check points
37
what are the actor classes used in memento dp? describe what they do.
- Memento - contains current state of an object - originator [ TextArea ] - creates and stores states in the Memento object [ snapshots ] - Caretaker [ editor ] - restores object state from the Memento object [ list of snapshots yizo vibe ]
38
what is the intent of the memento dp?
- captures and externalizes an objects state with out violating its encapsulation - since it can only be accessed by the class its contained under - it will not expose internal data of an object to objects outside the class
39
how many interfaces does a memento have?
- 2 - originator sees a wide interface - caretaker sees a narrow interface
40
___________ is responsible for memento's safekeeping?
caretaker
41
what are benefits of a dp?
AFFRII - provides access from experts to non experts - facilitates comm - facilitates design improvement - reuse of successful designs - improve design understandability - improve design doc