Created
May 13, 2020 17:25
-
-
Save ahojukka5/5a0615b28ef9aabf17f140caceb9f8a5 to your computer and use it in GitHub Desktop.
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 class AnotherData { | |
private final int data; | |
AnotherData(int data) { | |
this.data = data; | |
} | |
public int acquireData() { | |
return data; | |
} | |
} |
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 class Data { | |
private final int data; | |
Data(int data) { | |
this.data = data; | |
} | |
public int getData() { | |
return data; | |
} | |
} |
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 class DataLayer<T> { | |
protected T data; | |
public DataLayer(T data) { | |
this.data = data; | |
} | |
public int getData() { | |
throw new UnsupportedOperationException("Not implemented."); | |
} | |
} |
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 class DataManipulator<T> { | |
public DataManipulator(DataLayer<T> data) { | |
System.out.println(data.getData()); | |
} | |
} |
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 class Main { | |
public static void main(String[] args) { | |
Data D1 = new Data(42); | |
AnotherData D2 = new AnotherData(24); | |
ThirdData D3 = new ThirdData(69); | |
new DataManipulator<Data>(new DataLayer<>(D1) { | |
public int getData() { | |
return data.getData(); | |
} | |
}); | |
new DataManipulator<AnotherData>(new DataLayer<>(D2) { | |
public int getData() { | |
return data.acquireData(); | |
} | |
}); | |
new DataManipulator<ThirdData>(new DataLayer<>(D3) { | |
public int getData() { | |
return data.getData(); | |
} | |
}); | |
} | |
} |
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 class ThirdData { | |
private final int data; | |
ThirdData(int data) { | |
this.data = data; | |
} | |
public int getData() { | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment