Design patterns Flashcards

(11 cards)

1
Q

Abstract occurrence Pattern

A

Creating an occurrence class to represent individual things.

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

Context of AO pattern

A

Set of related objects which members share common info differing in big ways

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

Problem to solve with AO pattern

A

Need to duplicate objects without duplicating common info (eg duplicating data in customercontroller for oop)

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

Example scenario for AO pattern

A

Library multiple copies of the same book
Author, title etc the same, maybe id is different to distinguish, should we replicate objects?? NO

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

Solution to AO Pattern

A

Occurrence class.
One to many class between the abstraction and the occurrence
Abstraction class has all common elements
Occurrence class contains diff elements

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

Delegation pattern

A

Allows object composition ( a part of ) to achieve the same code reuse as inheritance.

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

How is this achieved?

A

An object handles a request by delegating it to a second object, the second object is a helper object to the original object

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

Why do this?

A

Composition is favourable over inheritance and has several advantages over inheritance.

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

Singleton Pattern

A

Only one instance of a class. Single point of access for the class

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

How to implement the singleton pattern?

A
  1. Static member containing instance of the class
  2. Private constructor where the single new instance is made
  3. Static public helper getter function to allow other objects to use this object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why?

A

We use this pattern when we only want a single instance of the class to be created in our app ie loggers, db connectivity

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