次の設計要件があります。
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オブジェクトを使用して呼び出す必要があります。