I am new to java, and while I am reading the documentation, I cannot find any good ways to program with free communication between objects. For most languages that I know (C ++, C #, python, javascript), I can manage objects as having “signals” (notification of something happening / something is needed) and “slots” (a method that can be connected to a signal and process notification / to do some work). In all the languages mentioned, I can write something like this:
Object1 = new Object1Class(); Object2 = new Object2Class(); Connect( Object1.ItemAdded, Object2.OnItemAdded );
Now, if object1 calls / emits ItemAdded , the OnItemAdded Object2 method OnItemAdded Object2 . This loose-call technique is often called "delegates," "signal slot," or "control inversion." Compared to an interface, the technology mentioned does not require signal grouping into some interfaces. Any object methods can be associated with any delegate if the signatures match (C ++ Qt even extends this, allowing only partial signature matching). Therefore, I do not need to write additional interface code for each method / groups of methods, provide a standard implementation for interface methods that are not used, etc.
And I don't see anything like it in Java :( Maybe I was looking for the wrong way?
source share