策略模式

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();
    }
}

 

posted on 2022-04-21 07:54  金满仓  阅读(30)  评论(0编辑  收藏  举报

导航