博客
关于我
三、设计模式之抽象工厂模式(创建型)
阅读量:229 次
发布时间:2019-02-28

本文共 2184 字,大约阅读时间需要 7 分钟。

????????

?????????????????????????????????????????????????????????????????????????????????????????????????????

??????

?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

???????????

?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????????

???

  • ??????????????????????????????????????????????????????
  • ?????????????????????????????????????????????????
  • ?????????????????????????????????????????
  • ???

  • ???????????????????????????????????????????????????????-???????
  • ?????????????????????????????????????
  • ???????????

  • ?????Creator??????????????????????????????????????????????????

  • ?????Concrete Creator????????????????????????????????????NorthFactory ? SouthFactory ???????????????????????

  • ?????Product????????????????????????????????Fruit ????????????????

  • ?????Concrete Product????????????????? Apple ? Banana ????????? Fruit ????????

  • ?????????????

    ???????????????????????????????????????????????????????????????????

    ??????

    public interface FruitFactory {    // ????    public abstract Fruit createApple();    // ????    public abstract Fruit createBanana();}

    ??????

    public class NorthFactory implements FruitFactory {    @Override    public Fruit createApple() {        return new NorthApple();    }        @Override    public Fruit createBanana() {        return new NorthBanana();    }}

    ??????

    public abstract class Fruit {    public abstract void collect();}public class NorthApple extends Fruit {    @Override    public void collect() {        System.out.println("??????");    }}public class NorthBanana extends Fruit {    @Override    public void collect() {        System.out.println("??????");    }}

    ????????

    ??????????????????????????????????????????????????????????????????????????????????

    ??????

    ????????????????

    ????????????????????????

    ???????????????????????????????????TropicalFactory????????createApple?createBanana???????????????????????????????????-?????

    ??

    ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    转载地址:http://sgrs.baihongyu.com/

    你可能感兴趣的文章
    MySQL排序的艺术:你真的懂 Order By吗?
    查看>>
    Mysql推荐书籍
    查看>>
    Mysql插入数据从指定选项中随机选择、插入时间从指定范围随机生成、Navicat使用存储过程模拟插入测试数据
    查看>>
    MYSQL搜索引擎
    查看>>
    mysql操作数据表的命令_MySQL数据表操作命令
    查看>>
    mysql操作日志记录查询_如何使用SpringBoot AOP 记录操作日志、异常日志?
    查看>>
    MySQL支持的事务隔离级别,以及悲观锁和乐观锁的原理和应用场景?
    查看>>
    mysql支持表情
    查看>>
    MySQL支撑百万级流量高并发的网站部署详解
    查看>>
    MySQL改动rootpassword的多种方法
    查看>>
    mysql数据分组索引_MYSQL之索引配置方法分类
    查看>>
    mysql数据取差,mysql屏蔽主外键关联关系
    查看>>
    MySQL数据和Redis缓存一致性方案详解
    查看>>
    MySQL数据和Redis缓存一致性方案详解
    查看>>