oop - Set Content inside Interface Java -
oop - Set Content inside Interface Java -
i'm learning interface , i'm faced problem of how give content within interface.
i read article http://pixelscientists.com/blog/posts/drag-and-drop-inventory-with-libgdx-part-i
and content made me think - when uses interface within that
public interface slotlistener { void haschanged(slot slot); }
and creates this
private void notifylisteners() { (slotlistener slotlistener : slotlisteners) { slotlistener.haschanged(this);//this slot class } }
how give haschanged() method content? don't grasp thought of interface... mean, no content within haschanged() (of course of study because it's interface) why point slot class? , content method take , how?
maybe need see link above problem.
i take googled larn interfaces found basic tutorials, not cases this. asked problem in communities no result.
this typical case of observer design pattern. in design pattern have collection of listeners (your slotlistener) , object (your slot) notify listeners when has changed. slot class should contain method addlistener(slotlistener sl)
add together listener slotlisteners list. after have create class implements slotlistener
public class mylistener implements slotlistener{ void haschanged(slot slot){ system.out.println("slot " + slot.tostring() + " has changed"); } }
java oop
Comments
Post a Comment