The intent of a sequence diagram is to model one way in which the society interacts. You typically have many sequence diagrams for a single class diagram because any society of classes will interact in many different ways. Notes should appear on most of the diagrams.
Notes are a great aid in helping you understand more fully the details associated with this sequence of events.
#Sample sequence diagram code#
The point is that developers who need to interpret this diagram and use it to construct code must have the information provided in the notes to do so effectively. I also may want to use a note to specify that when the TimeEventSource object notifies its listeners of a time change, it may notify multiple listeners, resulting in a loop. This note allows for a great deal of flexibility in the diagram, because the entire message sequence holds true regardless of what class I use in place of TimeChangeListener. You’ll notice that I have attached a note to the TimeChangeListener interface specifying that I will actually create a class that implements this interface.
Let’s walk through the sequence diagram in further detail. Notice the notes used in Figure A to enhance understanding. The ordering of the messages sent between objects is always read top to bottom and typically is read left to right. This message results in the addTimeChangeListener() method being triggered. In Figure A, the EventExample object sends a message to the TimeEventSource object. When developing Java applications, it’s quite common to use a pattern similar to this example to handle events within your application. So, I can demonstrate how class and sequence diagrams complement each other by looking at an example of the UML that simulates the standard Java event-handling mechanism. Many of the elements that compose the Unified Modeling Language (UML) have a precise mapping to the Java programming language. When an object sends a message to another object, it implies that the two classes have a relationship that must be shown on a class diagram. You can use a class diagram to illustrate the relationships between the classes, and the sequence diagram lets you show the messages sent among the instances of these classes and the order in which they are sent. Using sample class and sequence diagrams, you can see how UML conveys unambiguous code-mapping information to developers.Ĭlass diagrams, when used in conjunction with sequence diagrams, provide an extremely effective communication mechanism. UML is used as a representation of the Java programming language. Class and sequence diagrams work together to allow precise modeling