Who should create the instances and assign the implementation of the execution strategy?

When implementing a strategy template, how do you determine which class is responsible for:

  • Choosing a specific implementation of a specific strategy for moving to the Context class (assuming that the choice is based on some complex business logic, and not on a static flag)

  • Performing the above specific implementation and actually implementing it in the Context class

There seems to be some kind of objective guidance that covers this. I read several different OOP drawings (i.e., GRASP and SOLID ), but I still do not understand this specific issue very clearly.

+3
source share
3 answers

This is very close to the problems I experienced with the DI container. Check out here , Mark Semann’s wonderful answer.

+1
source

If you are trying to solve a specific situation, you are looking for an abstract factory template . A factory determines how to create a type family based on runtime information.

If you are interested in how to handle this situation in an abstract, you are looking for an Inversion of Control container that manages the organization and execution of dependencies. Registering a strategy would include conditional logic.

+1
source

-, Desing Patterns. GoF ( ):

?

: " , , , , " [AIS + 77, page x]. , , , , - . , .

...

The decision describes the elements that make up the design, their relationships, responsibilities and collaboration. The solution does not describe a specific concrete design or implementation, since the template is similar to a template that can be used in many different situations. Instead, the template provides an abstract description of the design problem and how its general arrangement of elements (classes and objects in our case) solves it.

0
source

Source: https://habr.com/ru/post/1726416/


All Articles