"Design mode" 21, Policy mode

Source: Internet
Author: User

1  PackageCom.shejimoshi.behavioral.Strategy;2 3 4 /**5 * Function: interface to work6 * Time: March 9, 2016 PM 8:53:347 * Cutter_point8  */9  Public InterfacetoworkTen { One     /** A * How to work -      */ -      Public Abstract voidWorkStyle (); the  -}

1  PackageCom.shejimoshi.behavioral.Strategy;2 3 4 /**5 * Function: walk to work6 * Time: March 9, 2016 PM 8:55:157 * Cutter_point8  */9  Public classWalkingworkImplementstoworkTen { One  A @Override -      Public voidWorkStyle () -     { theSystem.out.println ("Walk To Work"); -     } -  -}

1  PackageCom.shejimoshi.behavioral.Strategy;2 3 4 /**5 * Function: Use tool to go to work6 * Time: March 9, 2016 PM 8:57:357 * Cutter_point8  */9  Public classTooltoworkImplementstoworkTen { One  A @Override -      Public voidWorkStyle () -     { theSystem.out.println ("Use tool to go to work"); -     } -      -}

1  PackageCom.shejimoshi.behavioral.Strategy;2 3 4 /**5 * Function: Selection method6 * Time: March 9, 2016 PM 9:15:527 * Cutter_point8  */9  Public classSelectTen { One     Privatetowork tw; A      -      PublicSelect (String type) -     { the         Switch(type) -         { -          CaseWalk: -Walkingwork ww =Newwalkingwork (); +TW =ww; -              Break; +          Case"Using Tools": ATooltowork TTW =Newtooltowork (); atTW =TTW; -              Break; -         } -     } -      -     /** in * Implement the appropriate policy -      */ to      Public voidGetResult () +     { - Tw.workstyle (); the     } *}

1  PackageCom.shejimoshi.behavioral.Strategy;2 3 4 /**5 * Function: Define a series of algorithms, wrap them up one by one, and make them interchangeable with each other. 6 * Applicable: Many related classes are just differences in behavior7 * need to use different variants of an algorithm8 * Algorithms use data that the customer shouldn't know9 * Time: March 9, 2016 PM 8:49:34Ten * Cutter_point One  */ A  Public classTest - { -      Public Static voidMain (string[] args) the     { -Select st =NewSelect ("Walking"); - St.getresult (); -Select St2 =NewSelect ("Use Tools"); + St2.getresult (); -     } +}

Walk to work using tools to go to work

"Design mode" 21, Policy mode

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.