Current location - Trademark Inquiry Complete Network - Trademark registration - What is the difference between Command mode and Strategy mode?
What is the difference between Command mode and Strategy mode?

Difference:

1. The command object collects two types of information, one is the method name, and the other is the method parameters. The parameters are collected through the object Receiver.

The basic motivation of the Command mode is to decouple the initiation and actual execution of program actions, which is like a battlefield squad leader giving an order (Command): machine gun cover (Command object 1), infantry charge (Command object 2) , but how to actually fire the machine gun and how each infantryman charges are matters of execution and are not all planned by the squad leader. Different soldiers will have different charge paths, which is called "polymorphism". The decoupling mechanism of the Command mode can realize polymorphism and asynchronously (action initiation does not mean immediate execution).

2. Strategy does not need to collect method name information, but only calls a method of strategy.

The purpose of Strategy mode is to implement program behavior templates, that is, part of the actions in a program behavior are certain, and part of the actions are uncertain, but the certain parts have a certain relationship with the uncertain parts, such as a beverage filling assembly line: The first step is to prepare the empty bottle; the second step is to fill it with drinks; the third step is to seal it; the fourth step is to label it.

Stragtegy mode reveals the certainty of this step, but it is left to the specific Strategy implementation to determine what drinks to drink and what trademarks to put on. Therefore, it is polymorphic and synchronous, so the implementation is usually through the Call Back function or the so-called Sink mechanism (essentially still a Call Back function).