Structural Flashcards

1
Q

What is a structural design pattern?

A

A structural design pattern is concerned with how classes and objects can be composed to larger structures.

The pattern simplifies the structure by identifying the relationships.

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

What is an adapter pattern?

A

AKA Wrapper pattern, an adapter pattern converts the interface of a class into another interface that a client wants.

It can allow multiple incompatible objects to now interact, and it allows for re-usability of existing functionality.

It is primarily used when an object needs to utilize an existing class with an incompatible interface.

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

What is a bridge?

A

A bridge pattern decouples the functional abstraction of the implementation, so that the two can vary independently.

Also known as a “handle” or “body”.

It improves extensibility and hides the implementation details from the client.

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

What is a composite pattern?

A

A composite pattern allows clients to operate in a generic manner on objects that may/may not represent a hierarchy of objects.

It defines class hierarchies for primitive and complex objects, it makes it easier to add new components, and allows for flexibility of structure.

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

What is a decorator pattern?

A

A decorator pattern attaches a flexible additional responsibility to an object dynamically.

Also known as a “wrapper.”

it provides greater flexibility than static inheritance, changes can be made by coding new classes, and it can simplify coding.

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

What is a Facade pattern?

A

A facade pattern provides a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client.

Every abstract factory is an example of a facade.

The pattern shield the client from the complexities of the components, and it promotes loose coupling.

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

What is a Flyweight Pattern?

A

A flyweight pattern reuses existing objects by storing them, and only creates a new object when no matching object is found.

It reduces the number of overall objects and memory required.

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

What is a Proxy Pattern?

A

A proxy is an object representing another object. In essence, it provides the control for accessing the original object.

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

What are the structural design patterns?

A

Adapter,
Bridge,
Composite,
Decorator,
Facade,
Flyweight,
Proxy

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

Why is a Proxy Pattern a bad idea?

A

It hides how data is passed across the network within methods. It is much easier to rationalize between services if standard tools such as JSON or CSV are used.

Using a proxy pattern you’d have to use 11 getters and setters for 11 instances, using JSON you just have the JSON payload.

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

What is a Facade Pattern suboptimal?

A

1) it’s similar to an Abstract Factory

2) to qualify as a facade an API must live on only one object, which is rarely the case.

Facade: 1 object
Real World: N objects

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