Diagrams make a design easy to discuss. The Unified Modeling Language, UML, is the standard notation for drawing them.
Basic Structural Modeling with UML
UML is a graphical language for visualising, specifying, constructing and documenting software. Its diagrams are of two kinds. Structural diagrams, such as class and component diagrams, show the static parts of the system. Behavioural diagrams, such as use case, sequence and collaboration diagrams, show how the system acts. Models are drawn at several levels, from the overall view to the detail.
Definition: UML. The Unified Modeling Language, a standard graphical notation for describing the structure and behaviour of software systems.
Class Diagrams
A class diagram shows the classes of a system and the relations among them. A class is drawn as a box with three parts, the name, the attributes and the operations. Visibility is shown with + for public, - for private and # for protected. The main relations are association, a link between classes, aggregation, a whole-part relation where the part can exist alone, composition, a stronger whole-part relation where the part cannot exist without the whole, generalisation, which is inheritance and is shown by a hollow arrow, and dependency, shown by a dashed arrow. Multiplicity, such as 1 and 0..*, tells how many objects take part in a relation.
Use Case Diagrams
A use case diagram shows what the system does from the user's point of view. An actor, drawn as a stick figure, is a person or system outside the one being built. A use case, drawn as an oval, is a service that the system provides to an actor. A rectangle, the system boundary, encloses the use cases. Lines join actors to the use cases they take part in. The relation include shows that one use case always uses another, and extend shows an optional addition.
Table 3.3: Relations in a class diagram
| Relation | Meaning | Notation |
|---|---|---|
| Association | Classes are linked | Plain line |
| Aggregation | Whole and part, independent | Hollow diamond |
| Composition | Whole and part, dependent | Filled diamond |
| Generalisation | Inheritance | Hollow triangle |
| Dependency | One class uses another | Dashed arrow |
Example 3.3: Class diagram for a library
Problem: Draw a class diagram for a library in which a Member borrows Books, and a Student and a Teacher are kinds of Member.
Solution:
- Create classes Member, Book, Student and Teacher.
- Show Student and Teacher as subclasses of Member by generalisation.
- Join Member and Book by an association named borrows with multiplicity 1 to 0..*.
Result: The diagram in the figure below shows the classes and their relations.
Common mistakes
- Using composition when the part can exist without the whole.
- Drawing the use case as a step of a process instead of a service to the actor.
- Putting too much detail into a diagram, which makes it unreadable.
Key takeaways
- UML has structural and behavioural diagrams.
- A class box has a name, attributes and operations.
- Composition is a stronger whole-part relation than aggregation.
- A use case diagram shows actors and the services of the system.
Practice questions
- What are the three parts of a class box?
- What does an actor represent in a use case diagram?
- What does a hollow triangle arrow show in a class diagram?
Answers to the practice questions
- Name, attributes and operations.
- A person or external system that interacts with the system.
- Generalisation, that is, inheritance.
Sources
- Official BCA syllabus Software Engineering, course code 26BCA403DS03, Unit III
