System Modeling

Based on Chp 5 of Sommerville “Software Engineering” (9th edition)

Introduction

system modeling is generally understood to be about creating graphical models of a system before implementing it in code

UML, the Unified Modeling Language, is a popular and standardized set of visual models for software

some popular types of UML diagrams

  • activity diagrams
  • use case diagrams
  • sequence diagrams
  • class diagrams
  • state diagrams

Activity Diagram

this diagram shows the process for how involuntary detention should be carried out for a patient suffering mental health problems that might be a danger to themselves or others

the filled-circle shows the begin and end of the activities

the arrows show the flow of activities

a long bar indicates that processes can be carried out in parallel (and all must be finished before going to the next step)

the value of such a diagram seems clear: it gives the precise steps of an important process in a compact way that is easy to understand

  • imagine if this was written in plain English — it would be a long mess of if-statements
Example activity diagram for involuntary detention, 5.2, Sommerville 9

Sequence Diagrams

used to model interactions between objects

  • e.g. human-database interaction, server-printer interaction, …

they diagram the interactions that take place during a single usage scenario

sequence diagrams are read from top to bottom

the “Alt” box shows a situation where alternative interactions are possible

Example activity diagram for involuntary detention, 5.6, Sommerville 9

Sequence Diagrams

this is another sequence diagram

Sequence diagram, 5.7, Sommerville 9

Class Diagrams: Association

a class diagrams shows how the classes in an object-oriented system relate to each other

in this diagram, class are in rectangles, and the lines show how the objects of that class associate

e.g. if class A and class B are in a 1 .. 1 (one-to-one) relation, then each object of class A is associated with one object of type B, and vice-versa

if class A and class B are in a 1 .. * (one-to-many) relation, then each object of class A is associated with 0 or more objects of class B

Class diagram, 5.9, Sommerville 9

Class Diagrams: Inheritance

this class diagram shows an inheritance hierarchy

intuitively, the arrows in this diagram can be thought of as “is a” links, or inheritance links, or subclass links

an arrow from a class points to another class that generalizes it

Class diagram, 5.11, Sommerville 9

Class Diagrams: Aggregation

aggregation models objects that are composed of other objects

for example, a car object might consist of an engine object, some wheel objects, and some seat objects

the diamond shape at the end of a line indicates aggregation in UML

Class diagram, 5.13, Sommerville 9

State Diagrams

state diagrams are a graphical way of describing many simple machines

it turns out that many parts of real-world programs can be nicely described as state machines

for example, in the diagram below, the boxes represent states of the system, and the arrows indicate events that can occur that might change the state

Class diagram, 5.16, Sommerville 9

State Diagrams

one general use of state diagrams is for problems related to parsing or tokenization

for example, suppose you want to write a program that will strip (remove) comments from a C++ program

C++ has both //-style comments and /* */-style comments

be careful: if // or /* or */ occurs inside a string, then they shouldn’t be removed

imagine you are processing a C++ file, character by character

in this scenario, and event is reading a new character

C++ comment state diagram, strings not handled

this version handles strings

C++ comment state diagram, strings not handled

Designing vs Documenting

one final thought about system models

they can be used in at least two different ways:

  1. before/during design as a way to create the design
  2. after design as a way to document the design

UML-like diagrams do seem to be useful in many cases as ways of documenting designs

but they often seem less useful as a tool for actually creating designs