次の設計要件があります。
interface Server {}public class ServerImpl implements Server {}、シングルトンである必要がありますpublic class ServerABC extends ServerImpl {}public class ServerXYZ extends ServerImpl {}
ここで、メソッドをクラスに入れたいのですが、Serverそれらの実装はまたはのいずれかで指定する必要がありServerABCますServerXYZ。
のServerImpl
public class ServerImpl implements Server {
private static Server server;
public static synchronized RESTClient getInstance() {
if (server == null) {
server = new ServerImpl ();
}
return server;
}
}
どうすればこれを機能させることができますか?
メソッドをServerインターフェイスに配置する場合、ServerImplそれを実装する必要がありますが、サブクラス(ServerABCおよびServerXYZ)に実装を提供する必要があります。これらのメソッドは、ServerImplオブジェクトを使用して呼び出す必要があります。