Structural Patterns Flashcards

1
Q

What is the Adapter Pattern

A

Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate
This is achieved by doing the following:
1. The adapter gets an interface, compatible with one of the existing objects.
2. Using this interface, the existing object can safely call the adapter’s methods.
3. Upon receiving a call, the adapter passes the request to the second object, but in a format and order that the second object expects.

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

What is the Facade Design Pattern?

A

Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes.
1. The Facade provides convenient access to a particular part of the subsystem’s functionality. It knows where to direct the client’s request and how to operate all the moving parts.

  1. An Additional Facade class can be created to prevent polluting a single facade with unrelated features that might make it yet another complex structure. Additional facades can be used by both clients and other facades.
  2. The Complex Subsystem consists of dozens of various objects. To make them all do something meaningful, you have to dive deep into the subsystem’s implementation details, such as initializing objects in the correct order and supplying them with data in the proper format.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the Proxy Design Pattern

A

Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

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

What is the Iterator Design Pattern

A

Iterator is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).
The main idea of the Iterator pattern is to extract the traversal behavior of a collection into a separate object called an iterator.

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

What is the Observer Design Pattern

A

Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
The object that has some interesting state is often called subject, but since it’s also going to notify other objects about the changes to its state, we’ll call it publisher. All other objects that want to track changes to the publisher’s state are called subscribers.

The Observer pattern suggests that you add a subscription mechanism to the publisher class so individual objects can subscribe to or unsubscribe from a stream of events coming from that publisher.

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

What is the Strategy Design Pattern

A

The Strategy pattern suggests that you take a class that does something specific in a lot of different ways and extract all of these algorithms into separate classes called strategies.

The original class, called context, must have a field for storing a reference to one of the strategies. The context delegates the work to a linked strategy object instead of executing it on its own.

The context isn’t responsible for selecting an appropriate algorithm for the job. Instead, the client passes the desired strategy to the context. In fact, the context doesn’t know much about strategies. It works with all strategies through the same generic interface, which only exposes a single method for triggering the algorithm encapsulated within the selected strategy.

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

What is the Strategy Design Pattern

A

The Strategy pattern suggests that you take a class that does something specific in a lot of different ways and extract all of these algorithms into separate classes called strategies.

The original class, called context, must have a field for storing a reference to one of the strategies. The context delegates the work to a linked strategy object instead of executing it on its own.

The context isn’t responsible for selecting an appropriate algorithm for the job. Instead, the client passes the desired strategy to the context. In fact, the context doesn’t know much about strategies. It works with all strategies through the same generic interface, which only exposes a single method for triggering the algorithm encapsulated within the selected strategy.

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