个人觉得:1) Properties.load(in)之后直接props.getProperty(key)就可以了,不用遍历转换成map, properties自身是继承Hashtable的。2)PropertiesReader用Singleton实现,可以避免多次重复读取配置文件。
2017-12-04
结合视频学习了
FactoryTest<PersonFactory> personFactory = new FactoryTest<>();
PersonFactory person = personFactory.getInstance(MCFactory.class);
Boy boy = person.getBoy();
boy.drawMan();
FactoryTest<PersonFactory> personFactory = new FactoryTest<>();
PersonFactory person = personFactory.getInstance(MCFactory.class);
Boy boy = person.getBoy();
boy.drawMan();
2017-11-19
FactoryTest<HairInterface> hairFactory = new FactoryTest<>();
HairInterface left = hairFactory.getInstance(LeftHair.class);
left.draw();
HairInterface left = hairFactory.getInstance(LeftHair.class);
left.draw();
2017-11-19
通用抽象工厂类:字数限制的太少了吧。
public class FactoryTest<T> {
public T getInstance(Class<? extends T> t) {
try {
return t.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
public class FactoryTest<T> {
public T getInstance(Class<? extends T> t) {
try {
return t.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
2017-11-19
这样吧。
public HairInterface getHairByClass(Class<? extends HairInterface> clazz) {
try {
return clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public HairInterface getHairByClass(Class<? extends HairInterface> clazz) {
try {
return clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
2017-11-19