Content of the events package

 

The "events" package

An "events" package is created (if it does not already exist) in the package of the class which owns the attribute or the association, on which the pattern was launched.  It is designed to contain a class representing each created class of events, as well as the interfaces and the adapters to be implemented or to be redefined, in order to listen to the events of these event classes.

 

 

The "Event" class

A class of events; which specializes the JDK's "EventObject" class, is created in the "events" package.  This class represents the event class previously entered.  Its name is obtained by concatenating the entered event class, (the first letter is converted to upper case if needed), with the "Event" string.  Objects of this class will be created each time an event, which has the type it represents, occurs.  This class contains:

·         an attribute or an association, with the same name as the element on which the pattern has been run, aimed at containing the new value of the attribute or association after the event has occurred.

·         a constant for each event of the event class.  The name of the constant is obtained from the event's name by adding "_" characters in front of the upper case letters, except for the first letter, and when putting the result in upper case.

·         two constants giving the interval in which the constants of the event class are defined, and which allow you to enumerate these events.  Their names are made up of the name of the event class put in upper case, and concatenated with "_FIRST" and "_LAST" respectively.

·         an "id" attribute designed to take the value of one of the constants representing the events, in other words, the type of event which occurred.

·         a constructor that takes the event's source object, the type of event and the new value of the attribute or association as parameters.

 

 

Interface

An interface which defines the methods to be redefined to react to the events of the event class is created in the package.  The name of this interface is made up of the event class name, the first letter of which is put into upper case if necessary, and concatenated with the "Listener" string.  This interface contains one method per event.  The names of these methods are made up of an event name.  The first letter is put in lower case if necessary.

 

 

Adapter

An adapter class implements the interface above and defines each method with an empty body.  A class such as this is defined each time an event class contains at least two events.  Indeed, the subscription is carried out through an event class and not through one event after the other.  However, sometimes we are not interested in all the events of an event class.  In this way, instead of implementing the interface, a listener can specialize this class and can only define the methods corresponding to the events to which it wants to react.