Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.84 KB | None | 0 0
  1. interface Toaster {
  2.    public void toast(String text);
  3. }
  4.  
  5. class DesktopToaster implements Toaster {
  6.    public void toast(String text) {
  7.     ...
  8.    }
  9. }
  10.  
  11. class AndroidToaster implements Toaster {
  12.    public void toast(String text) {
  13.       ....
  14.    }
  15. }
  16.  
  17. class MyApplicationListener implements ApplicationListener {
  18.    Toaster toaster;
  19.  
  20.    public MyApplicationListener(Toaster toaster) {
  21.       this.toaster = toaster;
  22.    }
  23.  
  24.    public void render() {
  25.       if(shit)
  26.          toaster.toast("Shit!");
  27.    }
  28. }
  29.  
  30. class DesktopStarter {
  31.    public static void main(String[] argv) {
  32.       new JoglApplication(new MyApplicationListener(new DesktopToaster()), ...);
  33.    }
  34. }
  35.  
  36. class AndroidStarter extends AndroidApplication {
  37.    public onCreate(Bundle ...) {
  38.        initialize(new MyApplicationListener(new AndroidToaster(), ...);
  39.    }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement