Template Methodology Design pattern (Templete method)Defines an algorithm skeleton in an operation, and delays the implementation of some mutable parts into subclasses.The template method design pattern allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.1 I
template ModeProblem ScenarioCoffee and tea are derived from abstract drinks, coffee and tea have the method of boiling water, so you can boil water to extract the method to the abstract beverage to achieve, and coffee with a coffee powder to the cup method, the tea set has a way to add tea to the cup, it looks like two methods are different logic, Abstract classes are referenced in many places by other types, that is, other types call abstract classe
/* Requirements: Gets the time that a program runs. Principle: Get the program start and end time and subtract. Get time: System.currenttimemillis (); When the code is optimized, you can solve this kind of problem. This way, the template method design pattern. What is a template method? When defining a feature, part of the feature is deterministic, but part of it
in speech recognition, the same words are the same person, each time the situation is different, difficult to identify. This chapter is a definition of how to adapt to different situations with different characteristic indicators.1, based on the best path search measure: ① the Bayesian optimality principle and dynamic programming ② editing distance (the edit Distance) ③ in speech recognition dynamic time warp (DTW), speaker-dependentrecognition. Speaker-independentrecognition.2, correlation-base
2018-05-06Template Method Design patternThe skeleton of an algorithm in an operation is defined in a method of the parent class, and some steps are deferred to the subclass because the implementation details of the different subclasses are different. The template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.Abstract Parent class: defines the business skeleton in the operation,
Template method Mode
English name
Template Method Pattern
definition
The skeleton of an algorithm is defined in a method, and some steps are deferred to subclasses, and the template method allows subclasses to redefine some of the steps in the algorithm without altering the algorithm structure.
Principles
H
In my design Journey: Strategy pattern (primary) (C + +) (OO C + +) (Template C + +), we used strategy pattern to let graph Er can draw triangle, circle and square
Because the need to change again,:D, we hope that Grapher will be able to print the text in each shape, the implementation of the results are as follows
Draw Hello Shape!! in Square Draw Hello C++!
Banktemplatemethod Abstract classPublic abstract class Banktemplatemethod {//Concrete method public void Takenumber () {System.out.println ("queue");} public abstract Void Transact (); Transact specific business//hook method public void Evaluate () {System.out.println ("Feedback Score");} Public final void process () {//Template Method!!! This.takenumber (); This.transact (); This.evaluate ();}}Test class Clientpublic class Client {public static void
(1) Template method definition:When defining a feature, part of the feature is deterministic, but part of it is indeterminate, and the identified part is using the indeterminate part,Then the uncertain parts are exposed. It is done by subclasses of the class.(2) Sample code:1 //get the execution time of a method2 Abstract classGetTime3 {4 Public Final voidgetTime ()5 {6 LongStart =System.currenttimemillis ();7 8 RunCode ();9 Ten
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.