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

本文共 2215 字,大约阅读时间需要 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/

    你可能感兴趣的文章
    Objective-C实现knight Tour骑士之旅算法(附完整源码)
    查看>>
    Objective-C实现KNN算法(附完整源码)
    查看>>
    Objective-C实现koch snowflake科赫雪花算法(附完整源码)
    查看>>
    Objective-C实现KPCA(附完整源码)
    查看>>
    Objective-C实现KruskalMST最小生成树的算法(附完整源码)
    查看>>
    Objective-C实现kruskal克鲁斯卡尔算法(附完整源码)
    查看>>
    Objective-C实现kth order statistick阶统计量算法(附完整源码)
    查看>>
    Objective-C实现lamberts ellipsoidal distance朗伯椭球距离算法(附完整源码)
    查看>>
    Objective-C实现Lempel-Ziv压缩算法(附完整源码)
    查看>>
    Objective-C实现levenshteinDistance字符串编辑距离算法(附完整源码)
    查看>>
    Objective-C实现logistic regression逻辑回归算法(附完整源码)
    查看>>
    Objective-C实现longestCommonSubsequence最长公共子序列算法(附完整源码)
    查看>>
    Objective-C实现LongestIncreasingSubsequence最长递增子序列算法(附完整源码)
    查看>>
    Objective-C实现lorenz transformation 洛伦兹变换算法(附完整源码)
    查看>>
    Objective-C实现Lower-Upper Decomposition上下分解算法(附完整源码)
    查看>>
    Objective-C实现lowest common ancestor最低共同祖先算法(附完整源码)
    查看>>
    Objective-C实现LRU 缓存算法(附完整源码)
    查看>>
    Objective-C实现LRU缓存(附完整源码)
    查看>>
    Objective-C实现lstm prediction预测算法(附完整源码)
    查看>>
    Objective-C实现lucas数列算法(附完整源码)
    查看>>