I have following design requirements:
interface Server {}public class ServerImpl implements Server {}, must be a Singletonpublic class ServerABC extends ServerImpl {}public class ServerXYZ extends ServerImpl {}
Now I want to put methods in class Server their implementation should be given by either ServerABC or ServerXYZ.
In ServerImpl
public class ServerImpl implements Server {
private static Server server;
public static synchronized RESTClient getInstance() {
if (server == null) {
server = new ServerImpl ();
}
return server;
}
}
How can I make this work?
If I put methods in Server interface, ServerImpl has to implement it but I want the subclasses (ServerABC and ServerXYZ) to provide implementation. These methods should be called using ServerImpl object.