[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
The template is no stranger to students studying C ++. Functions include template functions and templates. So what is the template mode? We can think about the nature of the template
Business requirements to implement a domain algorithm
Solution Solutions Template method mode, 2 characters:
Template class-Specification algorithm skeleton, encapsulation basic method, template method and Hook methodWhere the template method should be defined as final, preventing subcla
header file.
Example 10-1 reads a few integers from the standard input, stores them in a vector container, and outputs their opposite number.
STL Program ExamplesAn implementation of the transform algorithm:Template
The transform algorithm sequentially traverses the elements pointed to by first and last two iterators;
The value of each element as an argument to the op of the function object;
Outputs the return value of the OP through the iterator result sequence;
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. Straight to the point
Template method ModeDefines the skeleton of an algorithm in an operation, and delays some steps into subclasses. The template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm. Popular is that there are a lot of the same steps, in some places there may be some differences suitable for this mode, such as the big talk
the subclass. The template method allows subclasses to redefine some specific steps of an algorithm without altering the structure of an algorithm.roles in the patternAbstract class (AbstractClass): The template method is implemented, and the skeleton of the algorithm is defined.Concrete Class (Concreteclass): Implements the abstract method in the abstract class, has completed the complete algorithm.Public
A joke says: How many steps does it take to put an elephant into a refrigerator?
One, open the refrigerator
Two, put the elephant in
Three, close the refrigerator
In the same vein, how many steps does it take to put a lion in the freezer?
One, open the refrigerator
Two, put the Lions in
Three, close the refrigerator
In the above example, do you find that the two methods have a common step, but the specific implementation is slightly different, in short, these two types of behavior can share a s
This article continues to introduce the template method pattern of 23 design pattern series. OverviewThe 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, and then declare some abstract methods to force subclasses to implement the remainin
JavaScript: Template Method of Design PatternIntroduction
The template method (TemplateMethod) 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.
Th
of an algorithm at one time, and leave the variable behavior to the subclass for implementation.
Common behaviors in each subclass should be extracted and centralized into a common parent class to avoid code duplication. differences are separated into new operations. Finally, replace these different codes with the template method of A New phishing operation.
Control subclass extension. The template m
Template method is better understood, is to avoid code redundancy, implementation of code to take the function. For example, the most common tea and coffee, two have a lot in common, all need to boil water, all need to pour into the cup, then these repeated methods can be drawn out, placed in the parent class, as for the different methods, write an abstract class, so that different subclasses to rewrite the parent class.CodeTemplate classPackage
template method pattern:1, good package 2, good reuse, 3, shielding details 4, easy to maintainAs for the disadvantage, it is the inheritance problem, in Java can only inherit a parent class.Process: Analyze scenes---step----Refactor code--important, complex algorithms, core algorithms designed as templatesNote the point:Template method needs to be declared as public finalThe private method is the basic logicProtect abstract method is an extensible m
Although art is divided into independent fields, there are always similarities. Ui/ux design is also a kind of art, like art, Ui/ux's design also need a lot of copying other excellent works to improve their level.But as the saying goes: "Tiger", if you copy the object is not appropriate, it is likely to have its shape and not its meaning. So, where to find the right copy material, to do "Tiger painting Tige
= "Http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg"=new Webpimageloader (); Loader.downloadimage (IMAGEURL,200,200);Pattern mode Advantages and disadvantages: 1.) Advantages The template method pattern removes duplicate code from subclasses by moving the invariant behavior to the superclass. Subclasses implement some of the details of the algorithm, which facilitates the expansion of the algorithm.By invoking the subclass implementatio
Ec (2); this template is not the template engine of smarty, not template. Is an object-oriented design pattern. For example, in the easerver file, the ui part uses wxpython. I want to change it to qt, and I feel that the template can play a role in this function. The key poi
First, UML diagramSecond, the conceptTemplate Method Pattern: defines the skeleton of an algorithm in an operation, and delays some steps into subclasses. The template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.Third, the descriptionRole:(1) AbstractClass: abstract class, in fact, is an abstract template, defines and implements a
certain floating discount on the price; in short, quoting a customer is a very complex Java code:1 PackageOoad.design.Strategy;2 /**3 * Quoting interface4 * @authorHellokitty Yan5 *6 */7 Public InterfaceQuoteprice {8 Public DoubleQuoteprice (DoublePrice );9}1 PackageOoad.design.Strategy;2 3 Public classContent {4 PrivateQuoteprice Quoteprice;5 6 PublicContent (Quoteprice quoteprice) {7 Super();8 This. Quoteprice =Quoteprice;9 }Ten /** One * Discoun
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.