Last active
February 20, 2018 16:15
-
-
Save 256BitChris/2e7be835615c9ca3ee55622b7aee026e to your computer and use it in GitHub Desktop.
Java Glue Code Between Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooResult { | |
private int a; | |
private boolean d; | |
public FooResult(int a, boolean d) { this.a = a + 1 ; this.d = !d; } | |
public int getA() { return a; } | |
public boolean getD() { return b; } | |
} | |
// Very similar shape as FooResult, but has extra parameters. | |
// | |
// Can't extend FooResult because it extends another class for some reason. | |
class BarResult extends SomeOtherClass { | |
private int a; | |
private boolean d; | |
private Date creationDate; | |
public FooResult(int a, boolean d) { this.a = a + 1; | |
this.d = d;} | |
public int getA() { return a; } | |
public boolean getD() { return b; } | |
} | |
public FooResult foo(int a, string b, float c) { | |
return new FooResult(a, false); | |
}; | |
public BarResult bar(int a, boolean d) { | |
return new BarResult(a,d); | |
} | |
public BarResult bar(FooResult f) { | |
//Mapping parameters, specific to FooResult -> bar() parameters. | |
return bar(f.getA(), f.getD()); | |
} | |
public BazResult baz(FooResult f) { | |
//Mapping parameters, specific to FooResult -> baz() parameters. | |
return baz(f.getA(), f.getD()); | |
} | |
public BazResult baz(BarResult b) { | |
//Mapping parameters, specific to BarResult -> baz() parameters. | |
return baz(b.getA(), b.getD()); | |
} | |
public BazResult baz(int a, boolean d){ | |
return new BazResult(a, d); | |
} | |
FooResult fooResult = foo(1,"hello",2.0); // a == 1, d == false | |
BarResult barResult = bar(f); // a == 2, d == false; | |
BazResult bazResult = baz(x); // a == 3, d == true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment