An event is anything that happens to an object in a system.
Events appear in sequence and statechart diagrams.
Events can be internal (caused by another object in the system) or external (caused by an actor).
Events can be synchronous (predictable) or asynchronous (unpredictable).
A call event happens when an object's method is invoked.
A signal event is a message sent to an unknown recipient, examples include throwing an exception or broadcasting a state change. Signals are usually asynchronous.
A time event happens when time passes.
A change event happens when an object changes state.
Here's a simplified use case model for an ATM:
Here's an analysis/design model:
Note that exception classes are modeled as signal classes (i.e. classes with the <<signal>> stereotype). Although not visible in the diagram, the model specifies that the Account.deposit method raises (throws) InvalidAmount exceptions and the Account.withdraw method raises (throws) InvalidAmount and InsufficientFunds exceptions. These exceptions are caught and handled in the ATM class. Dependency arrows indicate that changes to the exception hierarchy may require changes in the Account and ATM classes.
Here's an interaction:
Message 1 is an asynchronous external call event because its source is an actor external to the system.
Message 2 is a synchronous internal call event.
Message 3 is an asynchronous, internal signal event, savings.withdraw(-100) is throwing an InvalidAmount exception.
Message 4 is a synchronous, internal call event. The ATM is catching and handling the exception (probably by displaying a message to the account holder).
Here's a simplified lifecycle model for the ATM (i.e., a statechart diagram):
Rectangles represent internal states of the ATM. Arrows represent transitions between states.
Transition labels have the format:
name: EventType : [guard condition] / action
All of these fields are optional.
Event e1 is an external, asynchronous event instance of type CardInserted, which is a call event.
Event e2 is an internal, synchronous event instance of type TimeOut, which is a time event.
Event e3 is an external, asynchronous event instance of type CommandEntered, which is a call event.
Transitions are examples of change events. For example, withdrawing more than $1000 from an account object might fire a change event. Interested actors and objects (such as FBI, DEA, NSA, and IRS) might be notified.