日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简单工厂模式定义

發(fā)布時(shí)間:2024/4/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简单工厂模式定义 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

簡單工廠模式(Simple Factory Pattern)是指由一個(gè)工廠對(duì)象決定創(chuàng)建出哪一種產(chǎn)品類的實(shí)例。

屬于創(chuàng)建型模式,但它不屬于GOF,23種設(shè)計(jì)模式。

public void setCurFormpublic void setCurForm(Gw_exammingForm curForm,String parameters)throws BaseException {try {JSONObject jsonObj = new JSONObject(parameters);ExamPaper examPaper = JSONObject.parseObject(parameters,ExamPaper.class);curForm = examPaper;}catch (Exception e){e.printStackTrace();}} public interface ICourse {/*** 錄制視頻* @return*/void record(); } public class JavaCourse implements ICourse {public void record() {System.out.println("錄制Java課程");} } ICourse course = new JavaCourse(); course.record(); public class CourseFactory {public ICourse create(String name){if("java".equals(name)){return new JavaCourse();}else if("python".equals(name)){return new PythonCourse();}else {return null;}}} public class CourseFactory {public ICourse create(String className){try {if (!(null == className || "".equals(className))) {return (ICourse) Class.forName(className).newInstance();}}catch (Exception e){e.printStackTrace();}return null;}} ICourseFactory factory = new ICourseFactory(); ICourse course = factory.create("com.leon.pattern.factory.JavaCourse"); course.record(); public ICourse create(Class<? extends ICourse> clazz){try {if (null != clazz) {return clazz.newInstance();}}catch (Exception e){e.printStackTrace();}return null; } CourseFactory factory = new CourseFactory(); ICourse course = factory.create(JavaCourse.class); course.record(); public class PythonCourse implements ICourse {public void record() {System.out.println("錄制Python課程");} } Calendar.getInstance(); public static Calendar getInstance() {return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT)); } private static Calendar createCalendar(TimeZone zone,Locale aLocale) {CalendarProvider provider =LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale).getCalendarProvider();if (provider != null) {try {return provider.getInstance(zone, aLocale);} catch (IllegalArgumentException iae) {// fall back to the default instantiation}}Calendar cal = null;if (aLocale.hasExtensions()) {String caltype = aLocale.getUnicodeLocaleType("ca");if (caltype != null) {switch (caltype) {case "buddhist":cal = new BuddhistCalendar(zone, aLocale);break;case "japanese":cal = new JapaneseImperialCalendar(zone, aLocale);break;case "gregory":cal = new GregorianCalendar(zone, aLocale);break;}}}if (cal == null) {// If no known calendar type is explicitly specified,// perform the traditional way to create a Calendar:// create a BuddhistCalendar for th_TH locale,// a JapaneseImperialCalendar for ja_JP_JP locale, or// a GregorianCalendar for any other locales.// NOTE: The language, country and variant strings are interned.if (aLocale.getLanguage() == "th" && aLocale.getCountry() == "TH") {cal = new BuddhistCalendar(zone, aLocale);} else if (aLocale.getVariant() == "JP" && aLocale.getLanguage() == "ja"&& aLocale.getCountry() == "JP") {cal = new JapaneseImperialCalendar(zone, aLocale);} else {cal = new GregorianCalendar(zone, aLocale);}}return cal; } LoggerFactory.getLogger(SimpleFactoryTest.class); public static Logger getLogger(Class clazz) {return getLogger(clazz.getName()); } public static Logger getLogger(String name) {ILoggerFactory iLoggerFactory = getILoggerFactory();return iLoggerFactory.getLogger(name); } public interface ILoggerFactory {Logger getLogger(String var1); } public Logger getLogger(String name) {Logger slf4jLogger = null;// protect against concurrent access of loggerMapsynchronized (this) {slf4jLogger = (Logger) loggerMap.get(name);if (slf4jLogger == null) {org.apache.log4j.Logger log4jLogger;if(name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {log4jLogger = LogManager.getRootLogger();} else {log4jLogger = LogManager.getLogger(name);}slf4jLogger = new Log4jLoggerAdapter(log4jLogger);loggerMap.put(name, slf4jLogger);}}return slf4jLogger;}

?

總結(jié)

以上是生活随笔為你收集整理的简单工厂模式定义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。