Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class BaseClass {
  2. //
  3. }
  4. class SubClass extends BaseClass{
  5. //
  6. }
  7. class Transformer{
  8. BaseClass base;
  9. public Transformer(BaseClass base){
  10. this.base = base;
  11. }
  12. public void transform(){
  13. //transforms the Object to a subtype-object
  14. // ???
  15. this.base = new SubClass(); //something like this (but not so!!!)
  16. }
  17. }
  18.  
  19.  
  20. class Programm{
  21. private List<BaseClass> list1 = new ArrayList<>();
  22. private List<BaseClass> list2 = new ArrayList<>();
  23. private List<BaseClass> list3 = new ArrayList<>();
  24. //many more Lists
  25. private List<BaseClass> listn = new ArrayList<>();
  26.  
  27.  
  28.  
  29. public void main() {
  30. BaseClass myObject = new BaseClass();
  31. list1.add(myObject);
  32. list2.add(myObject);
  33. list3.add(myObject);
  34. listn.add(myObject);
  35.  
  36. Transformer transformer = new Transformer(myObject);
  37. transformer.transform();
  38.  
  39. //required result
  40. // All Lists contain the transformed Object (from Type SubClass)
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement