开发者社区 问答 正文

Factory产生实例化对象没有意义的代码是什么呢?

已解决

Factory产生实例化对象没有意义的代码是什么呢?

展开
收起
JWRRR 2022-04-03 14:32:59 1368 分享 版权
1 条回答
写回答
取消 提交回答
  • 推荐回答

    public static IFruit getInstance (String className) {

    if (“apple”.equals(className)) {

    return new Apple() ;

    }

    if (“orange”.equals(className)) {

    return new Orange() ;

    }

    Return null ;

    }

    }

    class Apple implements IFruit {

    public void eat() {

    2022-04-03 14:41:03
    赞同 展开评论
问答地址: