Object-oriented design patterns Flashcards

1
Q

creational design patterns

A
  • how objects can be created
    • maintainability
    • control
    • extensibility

singleton
factory method

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

structural design patterns

A
  • how to form larger structures
    • management of complexity
    • efficiency

decorator

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

behavioural design patterns

A
  • how responsibilities can be assigned to
    objects
    • objects decoupling
    • flexibility
    • better communication

iterator
observer

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

design pattern

A

a reusable form of a solution to a common design problem

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

essential parts of a design pattern

A

pattern name
intent (what does it do?, what issue does it address?)
solution (basic elements providing a solution)
consequences (results and trade offs)

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

singleton

A

intent: ensure that only one instance of a class is allowed within a system; controlled access to a single object if necessary
consequences: controlled access to sole instance; reduces name space -> less global variables; permit also a variable number of instances

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

factory method

A

intent: abstract the process of object creation so that the type of the created object can be determined at run-time
- make a design more customisable in terms of which objects can be created
- want to avoid new operator because you don’t want to hard code which class you want to instantiate

consequences: you have a dedicated class for creating instances of objects
- you can pass arguments to that class for controlling the features of the objects you want to create

problem: The creation of subtype instances is hard-coded,
resulting in poor maintainability

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

decorator

A

intent: attach additional responsibilities to an object dynamically
- a flexible alternative to subclassing for extending functionality
- the number of classes within a hierarchy tree may explode

consequences: you can add responsibilities to individual objects, not to an entire class
- you can add. and combine responsibilities to individual objects, not to an entire class
- you can add and combine responsibilities transparently -> without affecting other objects
- you can also remove responsibilities at run-time

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

iterator

A

intent: need to abstract the traversal of wildly different data structures from client code
- provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation
- polymorphic traversal of collections

consequences: you have encapsulated the internal representation of your attributes with cardinality > 1
- if you change their internal representation, you do not need to change client code
- you can use for each construct over them

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

observer

A

intent: to let one or more objects be notified of state changes in other objects within the system
-state changes in one or more objects should trigger behaviour in other objects

consequences: support for broadcast communication
- when one object changes state, all its dependents are notified and updated automatically
- you can add or remove observers without modifying the subjects

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

iterator interface

A
  • formally defines what “iterating” means
  • once you implement such interface, your client can iterate over your elements in the same way

+hasNext()
+next()

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

iterrable interface

A

Now, to iterate over an object (polymorphically) we can
simply iterate over its returned iterator

+ Iterator<T> iterator()</T>

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

observer design decisions

A

inheritance vs. interface
scope of callbacks: multiple vs. single
control flow: internal vs. external calls to Notify()
data flow: push vs. pull

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