class and then derive multiple sub-classes, such as forward, center, and defender, based on it. But it is not the best solution, as we have discussed earlier-a player can be a forward player at a certain moment, and another moment becomes a center. At least in our football engine, this is our design problem.
Specific design problems: players have additional responsibilities, such as power forward and defender, and can switch during operation.
Problem
Java design pattern: template method pattern or template design pattern (behavior pattern), java Design Pattern
Abstract class, the unchanged code is written, and the part to be changed
and specific sub-classes. One designer is responsible for providing the outline and skeleton of an algorithm, while other designers are responsible for providing the logical steps of this algorithm. The method representing these specific logical steps is called the basic method. The method that aggregates these basic methods is called the template method ), the name of this design pattern is from here.Ii.
Java Design Pattern template method pattern, java Design Pattern TemplateTemplate Method Mode
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 withou
Java Design Pattern Template Method (template Method), design pattern Template
This article continues to introduce the template method modes of the 23 design patterns series.
Overview The temp
Template methods (Template method) mode
Prepare an abstract class, implement part of the logic in the form of concrete methods and concrete constructs, and then declare some abstract methods to force subclasses to implement the remaining logic. Different subclasses can implement these abstract methods in different ways, thus having different implementations of the remaining logic. This is the purpose of th
Introduction of Template Method pattern (Brief Introduction)
Template method Patterns (Template methods pattern) that define an algorithm skeleton in an operation and delay some steps into subclasses. Template methods allow subcl
Template Method pattern (JAVA) of software design pattern, design pattern java
What is the template method mode?
Defines the skeleton of an algorithm in an operation and delays these steps to the subclass. The template method allo
(); Buildinputpart (); } } /// ///Assembling HP Computers/// Public classAssemblehpcomputer:assemblecomputer { Public Override voidBuildmainframepart () {Console.WriteLine ("assembling the motherboard for your HP PC"); } Public Override voidBuildscreenpart () {Console.WriteLine ("assembling the display of an HP computer"); } Public Override voidBuildinputpart () {Console.WriteLine ("assembling the keyboard and mouse of the HP computer"); } } /// /
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
Today is five. Four Youth Day, I wish you a happy holiday. Look at today this title has appetite, summer, vinegar and shredded potatoes and fried balsam pear suitable for summer to eat, good eat fire. These two dishes should be eaten by most people, especially vinegar and shredded potatoes, as one of the masterpieces of "Shandong Cuisine" is known to the public, vinegar shredded potatoes, good eat fire. Stir fry bitter gourd this dish is good, is also the summer essential fine vegetable, its eff
Mode Motive:
1, template method mode is based on the inheritance of code reuse Basic Technology, template method pattern structure and usage is also one of the core object-oriented design. In the template method pattern, you can put the same code in the parent class and put
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
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
Mode motivation:
1, template method pattern is based on the inheritance of code reuse Basic Technology, template method pattern structure and usage is also one of the core of object-oriented design. In Template method mode, the same code can be placed in the parent class, an
IntroductionReferring to the template, you can not help but think of life "CV template", "Paper template", "Word in the template", etc., in real life, the concept of templates is-there is a prescribed format, and then everyone may according to their own needs or circumstances to update it, such as resume
Defined
Template method mode
Defines the skeleton of an algorithm in an operation, and completes the implementation of some of the steps in a subclass.The template method pattern allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.
The template
PS One sentence: Eventually choose Csdn to organize the publication of the knowledge points of these years, the article parallel migration to CSDN. Because CSDN also support markdown grammar, Ah!"Craftsman Joshui Http://blog.csdn.net/yanbober" read the previous "command pattern" of the design pattern (behavioral type) http://blog.csdn.net/yanbober/article/ details/45500113OverviewTemplate method
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.