目录
看看 mybatis中的源码使用的工厂模式
1。mybatis底层用来生产 数据源的工厂DataSource 这个是 jDk 自带的 数据源,
public interface DataSourceFactory {
void setProperties(Properties var1);
DataSource getDataSource();
}
具体产品类 A
public class UnpooledDataSource implements DataSource { }
生产这个产品类A的具体工厂
public class UnpooledDataSourceFactory implements DataSourceFactory {
protected DataSource dataSource = new UnpooledDataSource();
public DataSource getDataSource() {
return this.dataSource;
}
}
实际产品B
public class PooledDataSource implements DataSource {}
生产B的工厂
public class PooledDataSourceFactory extends UnpooledDataSourceFactory {
public PooledDataSourceFactory() {
this.dataSource = new PooledDataSource();
}
}