Handlers, Pipelines, Plugins, Rules, Mappers (22%) Flashcards

1
Q

Which design pattern follows the handler chain ?

A

The chain of responsibility design pattern

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

What is the responsibility of each handler when its processing is complete ?

A

Calling the next handler in the chain or terminate the chain immediately

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

What is the sole entry point into a handler ?

A

The “Execute” method

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

Two handlers are part of the same handler chain if:

A

they both declare the same parameter and result object types

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

True or false.

As a best practice, all handlers should inherit from the HandlerBase class ?

A

True

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

Why do we need to decorate handlers with the DependencyName attribute ?

A

This allows the handler to be retrieved by name via the dependency locator.

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

Which method should continue an handler chain or break it ?

A

The the Execute method

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

What should be the last line of code of your handler to execute the next one?

A

return this.NextHandler.Execute(unitOfWork, parameter, result);

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

What should be the last line of code of your handler to break the handler chain?

A

return result;

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

What are mappers ?

A

Mappers are extension points of the Optimizely B2B Commerce platform.

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

What is the purposes of mappers?

A

Bridge the gap between the API presentation layer and the business logic layer (services) for both input and output.

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

Is it possible to inherit from Optimizely’s mapper classes ?

A

Yes

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

When you derive from a mapper class, where are you allowed to read additional information from the HTTP request and provide the information to the parameters object that will be used during the next handler chain ?

A

In the MapParameter method

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

True or false.

In a mapper, you should read information using the HttpContext directly in your handler chain extension?

A

False. The best practice is to collect all the information read from the HTTP request in the mapper and send it as properties to the parameters object for the handle chain.

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

Which method of a mapper allows us to intervene on the feedback of the handler chain (service result) and to pass it to the response object (API model) ?

A

The MapResult method

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

Where should the majority of customizations and modifications be located?

A

In the extensions of the handler chain and/or pipelines that are called during the execution of this handler chain.

17
Q

Where its the appropriate place to add properties to the API model, for any entity field that you would like to have available on the frontend ?

A

In a mapper class

18
Q

Where is the appropriate place to add “display” properties that can become handy on the frontend ?

A

In a mapper class

19
Q

Why should you move the logic of the private functions from the handler class to a service?

A
  • The values that these methods compute are possibly reusable in other places in the application.
  • Using a service will eliminate the duplication of code and make it usable elsewhere.
  • The service is also testable with unit tests, if the logic is complex enough and you want to perform test coverage.
20
Q

Pipelines are very similar to handler chains. Which statements are not true ? Pick 2.

  • Both follows the principles of the chain of responsibility design pattern.
  • Both can interrupt the execution.
  • A pipeline is made of classes, which are called “pipes” and handler chains are made of classes called handlers.
  • No need to specify the DependencyName attribute on a pipe class
  • The Execute method of an handler class simply returns the result.
A
Both can interrupt the execution is false.
Unlike a handler class, a pipe class cannot interrupt the execution of the rest of the pipeline.
The Execute method of an handler class simply returns the result is false.
The Execute method of a pipe class simply returns the result. No need to call the next pipe class.
21
Q

What is the responsibility of the mapper ?

A

The Mapper is responsible for transcribing the API Parameter to an object that the service layer can use, usually named ServiceParameter.

22
Q

What are the responsibilities of controllers?

A

Managing requests and responses

23
Q

True or False. Controllers are responsible to apply business logic?

A

False. They are responsible for managing the flow of the API request through the Mapper, then to the service, back into the mapper and send a response.

24
Q

Which are the 2 responsibilities of the mappers?

A
  • Mapping objects from the presentation layer (API model) to objects that the service layer can use (Service Parameter)
  • Mapping back the Service Result into an API model that the controller can send back into the response
25
Q

How do you create an handler chain?

A

Inject the HandlerFactory responsible for creating handler chains

Call the first Handler’s Execute method, which in turn will call the next Handler’s Execute method and so on