[英]One interface with all methods with multiple implementation class each implementing a subset of the methods from the interface
I am working on refactoring the data access layer for a project where I need to provide the business logic layer developers with a single interface for all DB interactions. 我正在为一个项目重构数据访问层,在该项目中,我需要为业务逻辑层开发人员提供用于所有数据库交互的单个接口。 Currently there is just one DAOImpl class implementing this interface but the class has bloated to 15000+ lines of code.
当前,只有一个DAOImpl类实现此接口,但是该类已经膨胀到15000多行代码。 Now I wish to move the methods from this class into multiple classes based on the type of object they handle.
现在,我希望根据它们处理的对象类型将方法从此类移至多个类。 The approach I have thought of is -
我想到的方法是-
I just wanted to validate my approach in this forum to see if I am doing things the right way or is there a better solution/pattern for this problem. 我只是想在此论坛中验证我的方法,以查看我是否在以正确的方式行事,或者是否有针对此问题的更好的解决方案/模式。
I would suggest to have it in Facade like style. 我建议在Facade之类的样式中使用它。 The main DAOImpl has references to all the sub DAOs delegating the calls to appropriate one.
主DAOImpl具有对所有子DAO的引用,这些子DAO将调用委派给适当的子DAO。
UPD: to illustrate the approach UPD:说明方法
interface DAO {
void doSomethingUser();
void doSomethingProject();
}
class DAOImpl {
private UserDAOImpl;
private ProjectDAOImpl;
public void doSomethingUser() {
UserDAOImpl.doSomethingUser();
}
public void doSomethingProject() {
ProjectDAOImpl.doSomethingProject();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.