23 Java Design Patterns of the "behavioral mode" template method pattern

Source: Internet
Author: User




Banktemplatemethod Abstract class

Public 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 Client

public class Client {public static void main (string[] args) {Banktemplatemethod BTM = new Drawmoney (); btm.process ();//Using Anonymous Inner class Banktemplatemethod btm2 = new Banktemplatemethod () {@Overridepublic void Transact () {SYSTEM.OUT.PRINTLN ("I want to save! ");}}; Btm2.process (); Banktemplatemethod btm3 = new Banktemplatemethod () {@Overridepublic void Transact () {SYSTEM.OUT.PRINTLN ("I want to manage! I have 20 million Korean coins ");}; Btm3.process ();}} Class Drawmoney extends Banktemplatemethod {@Overridepublic void Transact () {SYSTEM.OUT.PRINTLN ("I want to withdraw money!!!") ");}}


23 Java Design Patterns of the "behavioral mode" template method pattern

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.