【代码积累】replace constructor with factory
来源:互联网 发布:mac百度云下载速度慢 编辑:程序博客网 时间:2024/06/06 14:04
import java.util.concurrent.ConcurrentHashMap;public class Factory {private ConcurrentHashMap<String, Object> registedList = new ConcurrentHashMap<String, Object>();public void register(String name,Object object) {registedList.put(name, object);}private static Factory factory = null;public Vehicle createSpecifiedVehicle(String name) {return ((Vehicle)registedList.get(name)).createObject();/*This is not gonna work as when createSpecifiedVehicle is called the static blocks in sub-classes has not been * executed yet so registedList is actually empty.Static block in a class will be executed at the time the class * is being load,and only when the class is needed it will be loaded by ClassLoader.*/}public static Factory getInstance() {if( null == factory ) {synchronized(Factory.class) {if( null == factory ) {factory = new Factory();}}}return factory;}}
阅读全文
0 0
- 【代码积累】replace constructor with factory method
- 【代码积累】replace constructor with factory
- 简化函数调用之十二 :Replace Constructor with Factory Method(以「工厂函数」取代「构造函数」)
- 【代码积累】factory pattern without reflection
- java 代码细节(Replace Temp with Query)
- java 代码细节(Replace Method with Method Object)
- start with 、replace
- Replace Temp with Query
- Replace Conditional with Polymorphism
- Constructor argument with object matching
- Created with Setup Factory
- 代码积累
- 重构-代替类型代码几中方式的比较(Replace type code with ...)
- 重构-代替类型代码几中方式的比较(Replace type code with ...)
- refactoring笔记——代码重构的方法:Replace Temp with Query
- 使用Eclipse重构代码——Replace Temp with Query
- 代码重构(一)-用函数对象代替函数(replace method with method object)
- replace content with expression 和 replace with expression
- GPS定位+经纬度定位
- GIT
- php.ini-development 与 php.ini-production
- Linux scp 使用详解
- JAVA国际化配置
- 【代码积累】replace constructor with factory
- 机器学习|决策树算法与python实现
- requset&response
- 深入浅出Android Gradle构建系统(三:build task)
- Entity Framework 和 Sqlite
- JavaScript 数字去掉小数点后的0
- 阿里云 OSS 对象存储,测试访问策略
- 【代码积累】ScheduledAtFixRate test
- VS2010+Qt5.3.2中文显示乱码问题