Finished re-reading of "classes vs. interfaces"
3 import java.util.Collections;
8 public static void main(String[] args) {
9 System.err.println("showUsageOfAbstractClassAPI:");
10 showUsageOfAbstractClassAPI();
11 System.err.println("showUsageOfRequestResponseAPI:");
12 showUsageOfRequestResponseAPI();
15 private static void assertEquals(String msg, int expected, int real) {
16 System.err.println(" " + msg + " expected: " + expected + " was: " + real);
17 assert expected == real;
20 private static void showUsageOfAbstractClassAPI() {
21 class ProviderWrittenAgainstVersion1 extends api.classes.Compute {
23 public List<String> getData() {
24 return Collections.singletonList("Hello");
27 int index1 = api.classes.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
28 assertEquals("Hello was found", 0, index1);
29 int index2 = api.classes.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
30 assertEquals("Unknown was not found", -1, index2);
32 class ProviderWrittenAgainstVersion2 extends api.classes.Compute {
34 public List<String> getData() {
35 return Collections.singletonList("Hello");
39 public Map<String, String> getDataAndDescription() {
40 return Collections.singletonMap("Hello", "Says hello");
44 int index3 = api.classes.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
45 assertEquals("Found by description", 0, index3);
50 private static void showUsageOfRequestResponseAPI() {
51 class ProviderWrittenAgainstVersion1 implements api.request.response.Compute {
52 public void computeData(Request request, Response response) {
53 response.add("Hello");
56 int index1 = api.request.response.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
57 assertEquals("Hello found", 0, index1);
58 int index2 = api.request.response.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
59 assertEquals("Unknown not found", -1, index2);
61 class ProviderWrittenAgainstVersion2 implements api.request.response.Compute {
62 public void computeData(Request request, Response response) {
63 response.add("Hello", "Says hello");
67 int index3 = api.request.response.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
68 assertEquals("Description found", 0, index3);