0
点赞
收藏
分享

微信扫一扫

【移动安全】对webview漏洞的一些分析

洲行 04-12 21:00 阅读 1

外观模式:能为系统框架或其他复杂业务流程封装提供一个简单的接口。
例如抽奖过程中
设计模式,一定要敲代码理解

在这里插入图片描述

调用1(抽奖系统)

/**
 * @author ggbond
 * @date 2024年04月08日 10:34
 */
public class Lottery {
    public String  getId(){
        System.out.println("获取商品id");
        return  "00001";
    }
    public boolean  stockControl(String id){
        System.out.println("库存减一");
        return true;
    }
}

调用2(快递系统)

/**
 * @author ggbond
 * @date 2024年04月08日 10:38
 */
public class Delivery {
    public String  createSaleId(String id){
        System.out.println("商品打包,生产快递订单号");
        return  "00001";
    }
    public boolean  send(String id){
        System.out.println("发货");
        return true;
    }
}

门面

/**
 * @author ggbond
 * @date 2024年04月08日 10:43
 */
public class Facade {
    private Delivery delivery;
    private  Lottery lottery;

    public Facade( Lottery lottery,Delivery delivery) {
        this.delivery = delivery;
        this.lottery = lottery;
    }

    public void  toLottery(){
       String id= lottery.getId();//抽奖
        boolean f= lottery.stockControl(id); //库存管理
        if(true==f) {
            delivery.createSaleId(id);//生成订单信息
            delivery.send(id); //发货
        }

    }
}

客户端调用

/**
 * @author ggbond
 * @date 2024年04月08日 10:40
 */
public class Main {
    public static void main(String[] args) {
        //客户端进行抽奖(普通写法)
        Lottery lottery=new Lottery();
        Delivery delivery=new Delivery();
       String id=lottery.getId();
        boolean stockControl = lottery.stockControl(id);
        if (stockControl) {
            delivery.createSaleId(id);//生成订单信息
            delivery.send(id); //发货
        }

        //门面模式 抽奖封装,客户端执行封装好的一个服务方法。
        Facade facade=new Facade(lottery,delivery);
        facade.toLottery();
    }
}

结果

获取商品id
库存减一
商品打包,生产快递订单号
发货

总结

门面模式目的在于,封装个子系统代码流程,使其独立于复杂子系统。

代码下载

代码下载

举报

相关推荐

0 条评论