其他分享
首页 > 其他分享> > 策略模式

策略模式

作者:互联网

package com.life.design.strategy;

public interface Promotion {
    void show();
}
package com.life.design.strategy;

public class PromotionA implements Promotion {
    @Override
    public void show() {
        System.out.println("买一送一");
    }
}
package com.life.design.strategy;

public class Promoter {
    private Promotion promotion;

    public Promoter(Promotion promotion) {
        this.promotion = promotion;
    }

    public void promoterShow() {
        promotion.show();
    }
}
package com.life.design.strategy;

public class Client {
    public static void main(String[] args) {
        Promoter promoter = new Promoter(new PromotionA());
        promoter.promoterShow();
    }
}

 

标签:life,策略,void,模式,strategy,design,promotion,public
来源: https://www.cnblogs.com/tsai-87/p/16172625.html