first, the concept
Concept
UML diagram
Role
Usage Scenarios
In fact, we often used abstract class is the pattern to use, so basically belong to a better understanding of a pattern.
Second, practice
According to the above role, give the corresponding code
Abstract templates
/*** Abstract Template * *@authorAdministrator **/ Public Abstract classAbstracttemplate {/*** Declaration and implementation of template methods*/ Public voidTemplatemethod () {//calling methods implemented by subclassesOperation1 (); Operation2 (); //call a method that has already been implementedOperation3 (); } Public Abstract voidOperation1 (); Public Abstract voidOperation2 (); Private Final voidOperation3 () {//has been implemented }}
Specific templates
/*** Specific Template * *@authorAdministrator **/ Public classConcretetemplateextendsabstracttemplate{@Override Public voidOperation1 () {//Basic Method Implementation} @Override Public voidOperation2 () {//Basic Method Implementation }}
Java design Pattern (16)--template method pattern for behavioral patterns