Class and use case diagrams show structure and services. To show how objects work together in time, and how the software is divided into replaceable parts, other diagrams are used.
Sequence Diagrams
A sequence diagram shows how objects interact in time order. Each object is drawn at the top with a dashed vertical lifeline below it. Horizontal arrows between lifelines are messages, and time runs from top to bottom. A solid arrow is a call, a dashed arrow is a return, and a narrow rectangle on a lifeline shows when the object is active. A sequence diagram usually describes a single scenario of a use case, such as issuing a book.
Definition: Sequence diagram. A UML interaction diagram that shows the messages exchanged between objects in the order in which they occur.
Collaboration Diagrams
A collaboration diagram, called a communication diagram in later versions of UML, shows the same interaction but stresses the links between objects instead of the time. Objects are drawn as boxes joined by lines, and messages are written on the links with sequence numbers, such as 1: request and 2: check, to show the order. It is better at showing which objects are connected, while the sequence diagram is better at showing the order of messages. The two are equivalent and can be changed from one into the other.
Component Diagrams
A component diagram shows the software as components, which are replaceable parts with well-defined interfaces, and the dependencies among them. A component is drawn as a box with a small component symbol. A provided interface is shown by a small circle, called a lollipop, and a required interface by a half circle, called a socket. The diagram helps to plan the physical structure, such as modules, libraries and services, and it is used to see how the pieces fit together.
Model-based design also uses state diagrams, which show the states of an object and the events that move it from one state to another, and activity diagrams, which show the flow of work like a flowchart with parallel paths. A deployment diagram shows how software components are placed on hardware nodes such as servers and devices. Together with the diagrams above, these give a complete picture of a design. In practice, a team draws only the diagrams that are useful for the system, and keeps them up to date because an outdated diagram is worse than none.
Table 3.4: Behavioural and structural diagrams
| Diagram | Shows | Stresses |
|---|---|---|
| Sequence | Messages between objects | Time order |
| Collaboration | Messages between linked objects | Links |
| Component | Replaceable parts and interfaces | Physical structure |
| Class | Classes and relations | Static structure |
Example 3.4: Sequence for issuing a book
Problem: Describe the messages in the scenario where a Member asks the Librarian to issue a book, and the Librarian checks the Catalogue.
Solution:
- Member sends issueBook(isbn) to Librarian.
- Librarian sends checkAvailability(isbn) to Catalogue.
- Catalogue returns true, and Librarian returns a due date to Member.
Result: The four messages are drawn in order from top to bottom in the figure below.
Common mistakes
- Putting messages out of time order in a sequence diagram.
- Showing the whole system in a single sequence diagram instead of one scenario.
- Confusing a component diagram, which shows software parts, with a class diagram.
Key takeaways
- A sequence diagram shows messages in time order along lifelines.
- A collaboration diagram stresses links and uses sequence numbers.
- A component diagram shows replaceable parts and their interfaces.
- Behavioural diagrams show how the system acts.
Practice questions
- What is a lifeline?
- How does a collaboration diagram show the order of messages?
- What does a component diagram show?
Answers to the practice questions
- The dashed vertical line below an object in a sequence diagram that shows its existence over time.
- By sequence numbers written on the messages.
- The replaceable parts of the software, their interfaces and dependencies.
Sources
- Official BCA syllabus Software Engineering, course code 26BCA403DS03, Unit III
