Advertisement
GeneralGDA

Hell Device

Mar 7th, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. interface NewRunnable<T>  
  2. {  
  3.     void buz(T argument);  
  4. }
  5.  
  6. abstract class CrazyDevice<T>  
  7. {  
  8.     private final NewRunnable<CrazyDevice<T>> delegate;
  9.     CrazyDevice(final NewRunnable<CrazyDevice<T>> code)  
  10.     {    
  11.         assert null != code;    
  12.         delegate = code;
  13.     }
  14.      
  15.     void work()
  16.     {    
  17.         delegate.buz(this);
  18.     }
  19.      
  20.     abstract T cast();  
  21. }
  22.  
  23. class HellPortal extends CrazyDevice<HellPortal>  
  24. {  
  25.     private final String name;
  26.     HellPortal(String name)  
  27.     {    
  28.         super(new NewRunnable<CrazyDevice<HellPortal>>()    
  29.         {    
  30.             @Override    
  31.             public void buz(CrazyDevice<HellPortal> key)    
  32.             {      
  33.                 key.cast().open();    
  34.             }    
  35.         });    
  36.         this.name = name;  
  37.     }
  38.  
  39.     @Override  
  40.     HellPortal cast()  
  41.     {    
  42.         return this;  
  43.     }
  44.      
  45.     void open()  
  46.     {    
  47.         System.out.println("The portal '" + name + "' is opened.");
  48.     }  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement