目录
看看 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();
}
}
本文介绍了MyBatis中使用工厂模式创建数据源的过程。通过DataSourceFactory接口定义了创建数据源的方法,具体实现如UnpooledDataSourceFactory和PooledDataSourceFactory分别用于创建不同类型的DataSource实例。
577

被折叠的 条评论
为什么被折叠?



