, , , executeFifthService() ServiceA ServiceB .. .
A, B .., , , .
:
ExecutesService:
public interface ExecutesService<T,S> {
public T executeService(S obj);
}
ServiceA:
public class ServiceA implements ExecutesService<Response1,Request1> {
List<Class> supportedListOfServices = new ArrayList<>();
//load list of classnames supported by ServiceA during startup from properties
public Response1 executeService(Request1 request1, Service service) {
if(!list.contains(Service.class)) {
throw new UnsupportedOperationException("This method should
not be called for this class");
} else {
return service.execute(request1);
}
}
}
ServiceB.
:
public interface Service<T,S> {
public T execute(S s);
}
FirstService:
public class FirstService implements Service<Request1,Response1> {
public Response1 execute(Request1 req);
}
SecondService, ThirdService ...
, Service ( FirstService SecondService ..) ServiceA , supportedListOfServices, UnsupportedOperationException.
, - ( , executeFifthService() ServiceA, B ..)), FifthService .