* Strategy mode (Strategy)



 GOF intent: The strategy pattern defines a series of algorithms, encapsulates each algorithm, and makes them interchangeable. ( Solutions where the same calling class has different strategies implemented under different strategies )

 

Role:

Environment class (Context): Use a Strategy object to configure. maintains a reference to the Strategy object

Abstract strategy class (Strategy): There is a method Algorithminterface () is a different implementation of the context's current strategy.

ConcreteStrategy: Concrete Strategy Class

 

Implementation points:

context is the main class, strategy is the context of different strategies. Set the context.setStrategy() strategy, the user calls context.contexInterface(), and the context directly calls the Algorithminterface() method in the strategy. Different methods are achieved under different strategies. Can be used in place of switch-case constructs.

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326802165&siteId=291194637