After working with VB6 for sometime I discovered the ?RaiseEvent? statement and found it to be very useful in creating classes that were abstract and could be reused easily. This allows objects to communicate to their parent objects (the objects that have instantiated a specific object) that something has happened within the object.
As I?m designing a real time model of a train in Java I need to be able to inform parent objects of events within other objects.
For example, in VB6 I have already created the train model with heavy use of events. In one particular subclass, the ?Engine? class fires off an event where it?s RPM (revs per minute) has changed. The beauty of this is that the object instantiated as class engine does not need to know about all other objects using it, but all objects using it can handle the fired event if they have a method declared to use it. I think this might be polymorphism, but I?m not sure.
Does Java allow this? Im aware of events in the awt package, but im not interested in those. I need to be able to create my own custom events.
Check out interface observer and class observable. Very quickly, a class tha extends observable has a list of classes that are aware of what is happening to it (Classes that implement observer), that is, every time something changes in this class all the observers of the behavior are notified so they can do whatever they want to do, for instance, updating a view, it is very used with the MVC pattern.