Section 4 · Unified Modeling Language (UML) Diagrams
On this page 10 headings
Learning goals: Read structural versus dynamic views; interpret class notation and sequence diagrams; describe the purposes of modelling.
UML uses several complementary diagrams to communicate both the stable structure and time-dependent behaviour of a proposed system.
UML: A Shared Blueprint Everyone Can Discuss
Software modelling is the creation of an external, explicit representation of the system we intend to build. A UML diagram is a common language for discussing a design before or during implementation. Different people on the team can inspect a shared model, spot missing relationships, and propose improvements.
There are many UML diagrams; a subset is used to create the design model. This course focuses mainly on class and sequence diagrams, as they are the most commonly used.
Structural View vs Dynamic Behavioural View
The structural view explains the relatively stable organisation of the software: its classes, attributes, methods, and relationships. For a Seller Portal, a structural picture might place Seller, Catalogue, and Product in a class diagram. It answers 'What parts exist and how are they linked?'
The dynamic behavioural view explains what happens during execution over time. A seller pressing Add might cause a request, a controller operation, a data update, and a response. It answers 'What happens first, next, and after that?' Both views concern the same software, but they are not interchangeable. One shows the building's plan; the other shows activity inside it.
Anatomy of a UML Class Box
A UML class box commonly has three stacked compartments. The top is the class name, here Product. The middle lists attributes, such as `− productId: String`, `− productName: String`, and `− productCost: Float`. The bottom lists methods, such as `+ addProduct(...)` and `+ deleteProduct(...)`.
The visibility symbols are important: `−` denotes private and `+` denotes public. The type after a colon indicates what sort of value an attribute stores. UML documents a *design*, not necessarily complete source code; ellipses in an illustration merely omit method parameters. When you draw one in an answer, preserve the class-name / attributes / methods order.
Exam clue: Top = name; middle = attributes; bottom = methods. − private, + public.
Seller Portal UML Class Diagram
This more complete Seller Portal class model contains Product, Catalogue, and Seller, plus specialised Product classes Clothing and Book. Product lists identifying attributes and basic operations. Catalogue refers to a product list and provides an operation to add products. Seller stores seller information and provides seller operations. Clothing adds size and colour; Book adds author and publisher.
Read the line endings carefully. A hollow triangle pointing toward Product expresses inheritance. The filled diamond on the Catalogue side of the Product–Catalogue link expresses the lecture's composition example. The directed link between Catalogue and Seller expresses a navigable association as shown in the diagram. The image is a simplified teaching model, so application-specific design choices may be different in real systems.
Practice: Find one inheritance, one whole–part link, and one association.
Three Dynamic Views: State, Activity, Interaction
A dynamic view can be represented in different ways. A state machine diagram describes how an object changes state in response to events. An activity diagram models the flow of control among different activities in a workflow. An interaction diagram emphasises messages exchanged among participating objects.
These viewpoints answer different questions: 'Which state is the object in?', 'What work is performed?', and 'Who communicates with whom?' The diagrams need not be used in every project or all at once. Designers choose the views that best reveal the logic or risk they need to understand.
Sequence Diagram: Lifelines and Messages
A UML sequence diagram is an interaction diagram showing which participant sends which message over time. Participants appear in boxes across the top. Dashed vertical lines beneath them are lifelines. Horizontal arrows show messages; the earliest appears higher on the page, and time moves downward.
In the simplified example, User enters details on UI Screen; UI calls `submit()` on Controller; Controller returns `success` to UI. The return arrow points back toward the caller. Do not draw a left-to-right time axis, because the horizontal direction is participant order, not chronological progression. Some diagrams use narrow activation bars to show execution intervals.
Exam clue: Messages run horizontally but time runs downward.
Complete Add Seller Sequence Diagram
The lecture's 'Add Seller' sequence has four participants arranged left to right: User, Add Seller UI Screen, Controller, and `:Seller`. User enters seller details. The UI calls `addSeller(id,name,address)` on Controller. Controller forwards the operation to the Seller object. Success then returns from Seller to Controller, from Controller to UI, and finally the UI informs User that the seller details were added.
The most useful exam technique is to read the message sequence from top to bottom and verify both its sender and its receiver. A return message must travel toward the earlier caller, not accidentally back in the request direction. The colon before `:Seller` is typical notation for an object/instance, not a new fifth participant.
Practice: Write six messages and identify sender and receiver for each.
Why Model with UML? Three Purposes
UML is a vehicle for communication and idea generation: key ideas like class names, some attributes and relationships let team members add classes or change relationships. It guides development of software: start with basic classes, then add attributes and member functions as development progresses.
There is a close correspondence with the implementation — every class in a model maps onto one or more classes in the code. Tools can generate code from detailed UML diagrams.
From a UML Class Model to Code
A model can be close enough to implementation that a tool can generate code skeletons from its structure. The illustration maps a Product class with `name: String`, `cost: Float`, and `addProduct()` to a small class definition and a method stub. Matching arrows show the direct correspondence.
Don’t get bogged down by the details, the variety of diagrams or the notation — use UML as a thought tool to think about, reason about and engage with your design.
Quick revision and self-check
Question: What do the three UML class compartments contain?
Answer: Class name; attributes; methods.
Question: What does a minus sign mean in UML?
Answer: Private visibility.
Question: In a sequence diagram, how does time run?
Answer: Downwards.
Question: Give one reason to make a UML model.
Answer: To communicate ideas, guide development, or generate code skeletons.
