design patterns Flashcards

1
Q

what are design patterns

A

reusable solutions to common problems that occur in software design

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

what are the 4 elements of a design pattern

A

name; description of the pattern in 2 or less words
problem; when you should use the pattern
solution; elements that make up the design and interactions responsibilities and relationships
consequences; trade offs of using the pattern

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

what are the 3 categories of design patterns

A

creational; techniques to create objects
structural; how classes are imposed in larger structures
behavioural; communication between objects

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

what is the observer design pattern

A

behavioural design pattern that allows you to define a subscription mechanism to notify other objects about any changes made in the object their observing

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

subject/publisher

A

the object that is changing state and informs observers

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

observers/subscribers

A

dynamically attached to the subject and can subscribe to event notifications

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

subject as an abstract class

A

abstract class defines add remove and notify observers
the concrete subject extends the abstract class
the concrete observer implements the observer interface and registers with concrete subjects to receive updates

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

subject as an interface

A

can add remove and notify observers
the concrete subject implements this and keeps a list of the observers and notifies them
the concrete observer implements the observer interface and registers with concrete subjects to receive updates

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

what is an adaptor design pattern

A

structural design pattern that converts the interface of a class into an interface that the client expects

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

what are the 4 classes needed for the adaptor

A

client; who wants to use the interface
target; the interface that the client uses
adaptor; adapts the adaptee to the target interface
adaptee; the existing interface that needs changing

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

class adaptor

A

adaps the adaptee by inheriting it and implementing the target interface

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

object adaptor

A

relies on composition
the adaptor implements the target interface and contains the adaptee instance to which it forwards the request

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

proxy

A

provides a placeholder for a real object to control access to it

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

what are 3 reasons for using proxies

A

authenticates a client
can create the subject on demand and only when needed
can stand in for something complex elsewhere

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

how does a proxy work (implementation)

A

both the proxy and the subject classes implement the subject interface whilst the proxy keeps an instance of the real subject
when the client wants to access the object it has to go through the proxy which requests the real object

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

remote proxy

A

provides a local representation for an object in a different address space

17
Q

protection proxy

A

validates access to the object
the proxy keeps an instance to the object which the client can only access through the proxy

18
Q

virtual proxy

A

enables the creation of expensive objects on demand
not all data from storage is loaded into memory when the object is called instead a list is kept of currently needed data therefore you only need to open the file when you need to add something to it

19
Q

builder

A

separates the creation of a complex object from its implementation so that the process can be used to create different representations

20
Q

how does a builder work

A

individual steps are separated into different methods and the director object specifies the steps in the correct order and different valued can be passed into the methods which will lead to different outcomes

21
Q

flyweight

A

optimising memory usage by sharing a common state amongst multiple objects

22
Q

how does a flyweight work

A

the flyweight interface has methods that the objects must have; unique data
the concrete implementation has objects that store shared data that can be used by many objects
the flyweight factory manages a pool of flyweight objects reusing them and only making new ones when necessary
the client passes in unique data whilst shared data stays the same