public Video getVideo(String type){ if ("java".equalsIgnoreCase(type)) { returnnew JavaVideo(); } elseif ("python".equalsIgnoreCase(type)) { returnnew PythonVideo(); } else { returnnull; } } }
测试类
1 2 3 4 5 6 7
publicclassTest{ publicstaticvoidmain(String[] args){ VideoFactory videoFactory = new VideoFactory(); Video video = videoFactory.getVideo("Java"); video.produce(); } }
if (name == null) { thrownew IllegalArgumentException("name argument cannot be null"); }
// 判断log类型返回root节点的logger if (Logger.ROOT_LOGGER_NAME.equalsIgnoreCase(name)) { return root; }
int i = 0; Logger logger = root;
// 如果缓存中已经存在的指定的logger,直接返回childLogger Logger childLogger = (Logger) loggerCache.get(name); // if we have the child, then let us return it without wasting time if (childLogger != null) { return childLogger; }
// 以下是创建logger的逻辑 String childName; while (true) { int h = LoggerNameUtil.getSeparatorIndexOf(name, i); if (h == -1) { childName = name; } else { childName = name.substring(0, h); } // move i left of the last point i = h + 1; synchronized (logger) { childLogger = logger.getChildByName(childName); if (childLogger == null) { childLogger = logger.createChildByName(childName); loggerCache.put(childName, childLogger); incSize(); } } logger = childLogger; if (h == -1) { return childLogger; } } }