C + + Theme--template method (template methods) mode
is now doing a differential system, presumably means that the server's code as a backup, the programmer from the server down to modify the code, and then submit the time to determine what has been modified, which did not, record the modified part, and then prepare to overwrite the modified part. Since our three people have not contacted MFC, so the song teacher to our request is not high, only to complete the basic function is good. Do the time encountered such a problem: We modify the time may be added files, add folders, modify files, in their records, to have different methods, but there will be the same steps, think of a half-day suddenly think of template method. Abstract records, as an abstract class record, define a recording method Writerecord, define a series of steps in this method Step1, Step2 ..., these steps are embodied in the record class as pure virtual functions, Then the three cases derive from the record as Diffilerecord, Morefilerecord, Morefolderrecord, which accepts the framework of the algorithm, and then implements the essence of the three algorithms, respectively. This is the basic idea of template mode.
The template method pattern provides a tradeoff between the two different types of functions that are not virtual (overwrite or retain) and virtual functions (themselves), and implement a common non-virtual function in the base class that calls the protected virtual function. The derived class retains the non-virtual functions of the base class and completes the implementation of the virtual function as required, by overriding the virtual functions to limit their own behavior in a limited way, but the steps are the same. The basic idea is to define an algorithm skeleton for an operation and delay the implementation step into subclasses, so that subclasses do not change the structure of an algorithm, but only the different parts of the implementation. The purpose of an abstract class is to capture common ground, while derived classes encapsulate different points.
is like the virtual bamboo and trinket have been monks, let them meditation, virtual bamboo may sat, and then the mind is the Scriptures, the final report to the old monk experience; trinket may be crooked sitting there, Then the mind is 18 touch, and finally made a lie to tell the old monk. The same three steps, sit-> think-> say, can abstract a monk class, make a meditation action, then make three meditation basic process sit, think, say. Derived from the virtual bamboo and trinket class, respectively, to achieve sit, think, say, although their process a touch, but their implementation varies. This is template method mode.