Created
October 4, 2013 17:21
-
-
Save yegorius/19f1c24706390a7af811 to your computer and use it in GitHub Desktop.
Mix-in style multiple inheritance
This file contains 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
public interface Elephant { | |
public int go(); | |
public int poop(); | |
} | |
public interface Orange { | |
public int pop(); | |
public int ripe(); | |
} | |
public class ElephantImpl implements Elephant { | |
@Override | |
public int go() { | |
return 1; | |
} | |
@Override | |
public int poop() { | |
return 2; | |
} | |
} | |
public class OrangeImpl implements Orange { | |
@Override | |
public int ripe() { | |
return 3; | |
} | |
@Override | |
public int pop() { | |
return 4; | |
} | |
} | |
public class ElephantOrange implements Elephant, Orange { | |
private final Elephant internalElephant; | |
private final Orange internalOrange; | |
public ElephantOrange() { | |
internalElephant = new ElephantImpl(); | |
internalOrange = new OrangeImpl(); | |
} | |
@Override | |
public int go() { | |
return internalElephant.go(); | |
} | |
@Override | |
public int poop() { | |
return internalElephant.poop(); | |
} | |
@Override | |
public int pop() { | |
return internalOrange.pop(); | |
} | |
@Override | |
public int ripe() { | |
return internalOrange.ripe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment