"Design Patterns" Android design mode-strategy mode self-view

Source: Internet
Author: User

Android strategy mode, mainly has 3 parts, algorithm abstract interface, a context object, specific algorithm three parts

The abstract interface implements some common shared methods.

The context object, for the specific method, callback processing. This is interface-oriented programming. To switch the corresponding algorithm

The concrete algorithm, is realizes with the abstraction interface.

Package com.ferris.strategy;/** *  algorithm interface, through the context to invoke the specific policy implementation method * @author Administrator * */public interface Basestrategy {public int daohang (int daohangfangshi);}

Package Com.ferris.strategy;public class Bikesrategy implements Basestrategy {@Overridepublic int daohang (int Daohangfangshi) {//TODO auto-generated method Stubreturn 0;}}

Package Com.ferris.strategy;public class Walkstrategy implements basestrategy{@Overridepublic int Daohang (int Daohangfangshi) {//TODO auto-generated method Stubreturn 0;}}
Package Com.ferris.strategy;public class Contextstrategy {/** * set policy, toggle a new policy */private basestrategy strategy;public Basestrategy Getstrategy () {return strategy;} public void Setstrategy (Basestrategy strategy) {this.strategy = strategy;} public void calbasesrategy (int index) {if (strategy!=null&&strategy instanceof basestrategy) {Strategy.daohang (index); Toggle the corresponding Algorithm}}}



"Design Patterns" Android design mode-strategy mode self-view

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.