i want to realize a messaging system over a custom-created listener model
to use only the very basics of a listener pattern, i want to create them right off from zero point, without using component listeners/ action listener
so heres my first try :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public interface MyListener { public void notifyit(Object e); }
class MrMoo { MyListener listener; public MyListener getListener() { return listener; } public void addListener(MyListener l) { if(l!=null) listener = l; } public void removeListener() { listener = null; } public void doit() { listener.notifyit(this); } }
public class ListenerTest { public static void main(String args[]) { MrMoo m = new MrMoo(); MyListener l = new MyListener() { public void notifyit(Object e) { System.out.println("!!!"); } }; m.addListener(l); m.doit(); } } |
i need some response if im on the right way, if there could be done something better etc