Skip to main content
edited body
Source Link
candied_orange
  • 114.6k
  • 27
  • 222
  • 352

The problem is this limit is specific to Service A. All other services that depend on DB do not need this limit.

Solution P: Abstract wayaway the problem

Resource r = service.fetchResource();    

Don't expect using code to deal with your little problems. Don't even ask it to know what it's talking to.

Classclass ServiceA implements Service  {
    public Resource FetchResource(...) {
        if (numberOfRoundTrips > ServiceDefinedLimit) {
            throw new Exception("Resource is too large");
        }          
        return DB.resource("A");  
    }
}

Don't expect other services to know anything about your weird problems either.

Classclass ServiceB implements Service {
    public Resource FetchResource(...) {
        //what round trips?
        return DB.resource("B");
    }
}

The problem is this limit is specific to Service A. All other services that depend on DB do not need this limit.

Solution P: Abstract way the problem

Resource r = service.fetchResource();    

Don't expect using code to deal with your little problems. Don't even ask it to know what it's talking to.

Class ServiceA implements Service  {
    public Resource FetchResource(...) {
        if (numberOfRoundTrips > ServiceDefinedLimit) {
            throw new Exception("Resource is too large");
        }          
        return DB.resource("A");  
    }
}

Don't expect other services to know anything about your weird problems either.

Class ServiceB implements Service {
    public Resource FetchResource(...) {
        //what round trips?
        return DB.resource("B");
    }
}

The problem is this limit is specific to Service A. All other services that depend on DB do not need this limit.

Solution P: Abstract away the problem

Resource r = service.fetchResource();    

Don't expect using code to deal with your little problems. Don't even ask it to know what it's talking to.

class ServiceA implements Service  {
    public Resource FetchResource(...) {
        if (numberOfRoundTrips > ServiceDefinedLimit) {
            throw new Exception("Resource is too large");
        }          
        return DB.resource("A");  
    }
}

Don't expect other services to know anything about your weird problems either.

class ServiceB implements Service {
    public Resource FetchResource(...) {
        //what round trips?
        return DB.resource("B");
    }
}
Source Link
candied_orange
  • 114.6k
  • 27
  • 222
  • 352

The problem is this limit is specific to Service A. All other services that depend on DB do not need this limit.

Solution P: Abstract way the problem

Resource r = service.fetchResource();    

Don't expect using code to deal with your little problems. Don't even ask it to know what it's talking to.

Class ServiceA implements Service  {
    public Resource FetchResource(...) {
        if (numberOfRoundTrips > ServiceDefinedLimit) {
            throw new Exception("Resource is too large");
        }          
        return DB.resource("A");  
    }
}

Don't expect other services to know anything about your weird problems either.

Class ServiceB implements Service {
    public Resource FetchResource(...) {
        //what round trips?
        return DB.resource("B");
    }
}