博客
关于我
三、设计模式之抽象工厂模式(创建型)
阅读量: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/

    你可能感兴趣的文章
    python-queue队列通信
    查看>>
    python-ros No module named PyKDL
    查看>>
    python-social-auth 是否需要会话
    查看>>
    Python再获年度编程语言,微软或成最大赢家
    查看>>
    python-week5
    查看>>
    Python写表情包搜索工具(非常详细)零基础入门到精通,收藏这一篇就够了
    查看>>
    Python-【1】配置
    查看>>
    Python-从子文件夹执行绝对导入
    查看>>
    Python-刷新页面,直到元素可单击
    查看>>
    PYTHON-唤醒+VOSK+DEEPSEEK+离线合成-实现纯离线大模型问答
    查看>>
    Python-在Dash回调中重用函数
    查看>>
    PYTHON-基本数据类型-元祖类型,字典类型,集合类型
    查看>>
    python-外观模式
    查看>>
    Python-如何使用FastAPI和uvicorn.run而不阻塞线程?
    查看>>
    Python-字典
    查看>>
    python-字符串
    查看>>
    Python-将二进制遮罩转换为多边形
    查看>>
    python-文件操作
    查看>>
    PYTHON-模块 sys os random shutil-练习
    查看>>
    Python-模块与包的管理
    查看>>