RequestResponse

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(Response Reply)
Line 3: Line 3:
Design pattern that solves the problem of growing parameters and return values from API methods. Beyond its basic purpose, it can help with delivering multiple results and providing the results in an incremental way, one by one. It also helps a lot with ability to cancel a computation in the middle.
Design pattern that solves the problem of growing parameters and return values from API methods. Beyond its basic purpose, it can help with delivering multiple results and providing the results in an incremental way, one by one. It also helps a lot with ability to cancel a computation in the middle.
-
TBD...
+
<source lang="java">
 +
public interface ComputeSomething {
 +
public void compute(Request request, Response response);
 +
 
 +
public static final class Request {
 +
private Request() {}
 +
 
 +
public int getArg1();
 +
public String getArg2();
 +
}
 +
 
 +
public static final class Response {
 +
private Response() {}
 +
 
 +
public void addResult(int r);
 +
public void addResult(String[] arr);
 +
}
 +
}
 +
</source>

Revision as of 19:54, 25 June 2008

Response Reply

Design pattern that solves the problem of growing parameters and return values from API methods. Beyond its basic purpose, it can help with delivering multiple results and providing the results in an incremental way, one by one. It also helps a lot with ability to cancel a computation in the middle.

public interface ComputeSomething {
    public void compute(Request request, Response response);
 
    public static final class Request {
        private Request() {}
 
        public int getArg1();
        public String getArg2();
    }
 
    public static final class Response {
        private Response() {}
 
        public void addResult(int r);
        public void addResult(String[] arr);
    }
}
Personal tools
buy