. NET design Pattern instance Template method mode (Template mothed pattern)

Source: Internet
Author: User

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 subclasses to redefine some specific steps of an algorithm without altering the structure of an algorithm. The template method pattern moves the invariant behavior to the superclass, eliminating the duplicated code in the subclass, and in fact the template method pattern provides a code reuse platform.

Ii. issues addressed (What to Solve)

To complete a process or a series of steps that are level-consistent in a particular detail, the individual steps are not implemented at a more detailed level, and you can use the template method pattern to solve the problem.

Three, template method pattern Analysis 1, template method pattern structure

Abstract class AbstractClass, implements a template method, defines an algorithm framework, the specific subclass will redefine PrimitiveOperation1 and PrimitiveOperation1 to implement an algorithm step.

Subclasses Concreteclassa and CONCRETECLASSB to implement PrimitiveOperation1 and PrimitiveOperation1 to complete the steps associated with a particular subclass in the algorithm.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.