DAOImpl
class should implement an interface DAOLayer
(say). You businessLogic class should be composed of a DAOLayer
object.
class BusinessLogic
{
/// ...
DAOLayer daoLayer;
public BusinessLogic(DAOLayer daoLayer)
{
this.daoLayer = daoLayer;
}
/// ...
}
class DAOImpl implements DAOLayer
{
/// ...
}
You should pass the actual implementation of DAOLayer
while creating BusinessLogic
class object.
Similar to following:
DAOLayer aDaoLayer = new DAOImpl();
BusinessLogic bl = new BusinessLogic(aDaoLayer);
OR
public BusinessLogic()
{
this.daoLayer = DAOFactory.create(true);
}
class DAOFactory
{
public static DAOLayer create(bool isDB)
{
DAOLayer aDao;
if(isDB)
{
aDao = // create for DB
}
else
{
aDao = // create for file
}
return aDao;
}
}