我有一个在技术上可行的RMI项目-但是,这有点混乱-目前,它绝对没有遵循SOLID的“单一责任原则”部分。
目前,我有4个接口耦合为1个接口。然后,我有一个实现此接口的系统。现在,此DBHandler包含所有4个接口的实现(我的所有SQL调用)(因此破坏了S)。但是,System也是我绑定到注册表的对象。
下面的简化示例
public interface User{
User getUserById(int id) throws SQLException;
}
public interface Role {
Role getRoleByName(String name) throws SQLException;
}
public interface SystemHandler extends User, Role {}
public class System extends DBAccess implements SystemHandler {
@Override
public User getUSerByid(int id) throws SQLException {
// SQL CALLS AND RETURN
}
@Override
public Role getRoleByName(string name) throws SQLException {
//SQL CALLS AND RETURN
}
}
public class ServerHandler extends UnicastRemoteObject implements ServerCalls {
//ServerCalls another interface of interfaces - so same issue here I suppose.
private SystemHandler systemHandler;
Public ServerHandler(Systemhandler systemhandler) throws RemoteException {
this.systemHandler = systemHandler;
}
}
public class Server {
public static void main(String[] args) throws Exception {
Registry registry = LocateRegistry.createRegistry(7788);
registry.bind("System", new ServerHandler(SystemHandler));
}
}
我的问题是,在谷歌搜索中似乎无法将不同的内容绑定到同一注册表-那么我该如何处理呢?