Register a callback function in other class
I am working on a program that contacts a PLC (programmable logic controller) using Java.
I have one class (Class A) that contacts the PLC and is able to add listeners for items changed inside the PLC (for example Input/Output changes).
Another class is the LED class (Class B). This graphically drawing a circle meant to show the status of an input or output.
Now I want the Class B to invoke a 'registration function' in Class A passing which Input/Ouput to observe. Class A then must create a listener function for that Input/Output. When the Input/Output changes the listener function will be called (this is handled by the PLC manufacturer software). The listener for that IO then must invoke a method in the Class B so that I can paint the correct status
The window handling, led painting (Class B) and PLC connection (Class A) I can all get to work. If I instantiate the LED from Class A it even works, however, I do not want the Class A to know anything about which items will be used.
Thus if I want to show the IO status with a LED I use a LED Class (Class B) or if I prefer a BarGraph, I will create a Class C.
Hope it is a bit clear what I want to establish. Almost all is working except that the LED class can register itself to de PLC Class to get a callback when the item changes.
Any hints / code samples would be highly appreciated. I am experienced programmer (VB, C) but just started with Java.