工厂模式小例子 getDaoImp
/**新建一个工厂类,创建dao层对象(单例模式)
*/
public class DaoFactory{
private static DaoFactory daoFactory;//私有化自身
private DaoFactory(){};//私有化构造方法
static{
if(daoFactory==null){
synchronized(DaoFactory.class){
If(daoFactory==null){
daoFactory =new DaoFactory();
}
}
//工厂模式
public static ConDao getDaoImpl(String daoImpl){
CanDao caodao = null;
if (daoImpl.equals("DetailDaoImpl")) {
caodao = new DetailDaoImpl();
} else if (daoImpl.equals("NewsCotegoryDaoImpl")) {
caodao = new NewsCotegoryDaoImpl();
} else if (daoImpl.equals("NewDaoImp")) {
caodao = new NewDaoImp();
}
return caodao;
}
}