In the book "Java and Patterns" of Dr. Shanhong, this describes the template method pattern: The template method pattern is the behavior pattern of the class. Prepare an abstract class, implement some of the logic in the form of concrete methods and concrete constructors, a
subclasses, so subclasses can expand the way to increase the corresponding function, in line with the opening and closing principles.Disadvantage: According to our design habits, abstract class is responsible for declaring the most abstract, the most general thing attributes and methods, implementation of the class to complete the specific things properties and methods. But the template method pattern is r
Make Web system development and maintenance more convenient, thereby effectively save manpower and material resources, by more and more enterprises of the green.
Template engine is an important method of the MVC pattern building process, the developer can design a set of meanings of the label, through the technical analysis processing effective data logic processing from the interface
1. Overview
Defines the skeleton of an algorithm in an operation, and defers the step to a subclass. Template methods enable subclasses to redefine some specific steps of an algorithm without altering the structure of an algorithm.
2. Role in the pattern
2.1 Abstract Class (AbstractClass): The template method is implemented, and the skeleton of the algorithm i
"Design pattern Refinement" Learning notes (14) ------Template method (Template method) mode
GOF : defines the skeleton of an algorithm in an operation, and delays some steps into subclasses. Template method enables subclasses to redefine certain steps of the algorithm without altering the structure of an algorithm
1. The SUMMARY
In this article, we have a comprehensive understanding of the template method pattern.
2. Job Search Newsletter
Oh, if you don't mind, I hope to do a job advertisement here.
Language direction: JAVA/C#/VB, language familiarity in descending order.
Job Orientation: development, testing and other IT related work.
Monthly salary Requirements: 1000 Yuan or more
Work Location: Beijing
3. S
method, Factory methods: Define an interface for creating objects, let subclasses decide which class to instantiate, and Factory method to defer instantiation of a class to subclasses.
Builder, Build mode: Separates the construction of a complex object from his presentation, allowing the same build process to create different representations.
Prototype, prototype mode: Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes.
("Hummerh1model3 horn called");} @Overridepublic void Engineboom () {//TODO auto-generated method StubSystem.out.println ("Hummerh1model3 engine Started");} @Overridepublic void Run () {//TODO auto-generated method Stubthis.start (); This.engineboom (); This.alarm (); System.out.println ("Hummerh1model3 ran Up");}} This is a basic template design pattern, but we can clearly see that there will be duplicate
The template method pattern defines the skeleton of an algorithm in one method, and some steps are deferred to subclasses. The template method allows subclasses to redefine some of the steps in the algorithm without changing the structure of the algorithm. A template is a method. This method defines the algorithm as a
1. Summary
In this article, we will give a comprehensive understanding of the template method mode.
2. Job Search Text message
Well, if you don't mind, I hope to make a job advertisement here.
Language direction: Java/C #/Vb. language familiarity is sorted in descending order.
Job orientation: development, testing, and other IT-related work.
Monthly salary: 1000 yuan or more
Work Location: Beijing
3. Open Doors
In the process of learning Java, we must have heard the design pattern of the term, in the industry there is such a word, if you can master 23 design patterns, then you are Daniel!Okay, no more nonsense, today I share with you one of the 23 design patterns Template Method Design patternFirst we need to know what is the template method design
C ++: prefer curiously recurring template pattern (crtp) to template pattern: http://www.codeproject.com/Tips/537606/Cplusplus-Prefer-Curiously-Recurring-Template-Patt
The "template pattern
Template Method Pattern : Defines the skeleton of an algorithm in an operation, and delays some specific steps into subclasses.The template method pattern allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.Structure diagram:AbstractClass is an abstract clas
Original: Http://www.tuicool.com/articles/6JBN7z3
If you are not yet aware of template method patterns and policy patterns, read the policy mode (strategy) and template method patterns first.
The main idea of the template method pattern is to define an algorithm flow, implement the specific steps, and defer to subcla
The source code is JDK1.8 as reference1. Definition:Defines the framework for an algorithm in an operation, and delays some steps into subclasses. Enables subclasses to redefine some specific steps of the algorithm without changing the mechanism of an algorithm.2. Analysis:General class Diagram:class Diagram parsing:The template method pattern is very simple and only uses the Java inheritance mechanism, but
of an algorithm. A the template method not only invokes primitive operations, it also invokes operations defined in AbstractClass or other objects. at -2. Concreteclass -Implements primitive operations to complete the steps associated with a particular subclass in the algorithm.Test class: 1 public class Test { 2 public static void main (string[] args) { 4 Temp Late temp = new Templateconcrete (); 5 Temp.update (); 6 7 } public
name of this design pattern is from here.
Template Method Mode Construction:
-The abstract template role has the following responsibilities:
Defines one or more abstract operations to implement sub-classes. These abstract operations are called basic operations, which constitute a step of top-level logic.
Defines and implements a
Template Method Mode
Definition: defines the skeleton of an algorithm in an operation, and delays some steps to the subclass. The template method allows the subclass to redefine certain steps of an algorithm without changing the structure of an algorithm.
For example, the exam copied by student A and student B is very similar. Except for different answers, the other questions are the same. If the instructor
Template Method Pattern Applet specific explanationThis address: Http://blog.csdn.net/caroline_wendyReference Template Method pattern: http://blog.csdn.net/caroline_wendy/article/details/32159455Template Method Pattern, an applet is a small program that can run on a Web page
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.