Comparison of Template Method Mode and Strategy Mode in Robert C. Martin's "Agile Software Developments: Principles, Patterns, Practices".
1. An example of the Template Method mode is given in the book. It is not the Template Method mode itself, but because the bubble is sorted in the base class, it is not a specific algorithm step by its derived class. It is not a good idea. Because this algorithm itself is implemented in a specific implementation (for the sort type), it is not possible to cope with the case of the exclusive algorithm itself, so the implementation of this mode becomes a mode. abuse.
2. Instead, use inheritance to increase the coupling of the algorithm step and the specific implementation method, violating the DIP principle: the interface isolation between the high-level module and the underlying module should be used.
3. As you can see from this example: Template Method mode is suitable for use in abstract general algorithms, and the STRATEGY mode applies to the case where the basic structure of the algorithm is more likely to change, and the implementation step has a variety of implementations. Therefore, the Strategy mode is more difficult to abstract, and the design of the two interfaces is particularly important.