Object Oriented Design and Development

Topic 4: Intro to Analysis and Design (Class diagrams and Use cases)

What we will cover this week

Introduction to analysis and design

What is Analysis and Design?

When building software, we need to ensure we create something which is what the user wants. To achieve this, we should perform analysis and design before we start coding. There are two components:

UML: Unified Modelling Language

Object-oriented analysis and design makes use of UML. UML is an extensive set of diagrammatic tools to enable developers to analyse a problem and design an object-oriented solution to the problem before coding it. These diagrammatic tools include (but are not restricted to):

UML is not an analysis and design process; rather it is a set of tools which can aid us in that process. It can be used in various different analysis and design techniques, such as ICONIX, discussed in a later week.

The problem statement

Analysis and design starts with a problem statement. This is a written description of what is required of the application, and will typically be produced by gathering requirements from the target users. Here is an example:

There is a requirement for a software application to allow a university 
to manage its undergraduate and masters students and modules. Each student and 
module is identified by a unique ID. University admins need to be able to look 
up students and modules by ID, look up students by name, and enrol students on 
modules. The system should record all modules a student is enrolled on.

Students are enrolled on a total of 6 modules.

It may be necessary to remove a student from the university or update the 
student's contact details.

What do we do with the problem statement?

We perform an analysis on the problem statement and derive two classes of artefact from it:

  1. The domain model and initial class diagrams. These represent potential classes in the system and how they interact. Thus, we are thinking of the system from a code-oriented point of view.
  2. The use case diagram. This is a diagram showing how users can interact with the system and what tasks different types of user can perform. Thus it is thinking of the system from a user-oriented point of view.

The domain model

The domain model is an initial diagram showing possible classes in the system, and their interaction. We derive it by:

  1. analysing the problem statement, and looking for nouns and their interactions - these are our first guess at classes in the system
  2. Having derived a list of possible objects, we then connect them together to illustrate the relationship between them

For example, for the student records application, specified in the problem statement above, we could identify likely nouns as below:

There is a requirement for a software application to allow a 
university to manage its undergraduate and masters students 
and its modules. Each student and module is identified by a 
unique ID. University admins need to be able to look up 
students and modules by ID, look up students by name, and enrol 
students on modules. The system should record all modules a student is enrolled 
on. 

Students are enrolled on a total of 6 modules.

It may be necessary to remove a student from the university or update the 
student's contact details.
These likely nouns appear: We also possibly have: but these are just simple items of data which could be represented as numbers and strings and therefore do not need their own classes. Furthermore we also have: but this is a bit different. The administrator will be a user of the software (an actor - see discussion on use cases below), not an entity that the software needs to manage. We consider users later, when doing use cases. So from this analysis we could derive a domain model as below:
Initial domain model - 
Student records system
This shows the three possible classes in the system, and the relationship between them as annotations.

Multiplicity

The domain model also includes multiplicity. Multiplicity is an indication of how many objects of each class are interacting with each other. The diagram above is indicating that:

Class diagrams

Class diagrams show the classes in the system, their inter-relationships, and the attributes and methods of each class. The class diagram is an extension of the domain model, with attributes and methods added.

How to derive the class diagram

Class diagram syntax

Each class is represented by a box, with content as follows:

Here is an example, based on the domain model above. Note that the addition of thesisTopic to the masters' student was not part of the domain model. I have added it here to help illustrate the inheritance hierarchy, but in a real case, you would not, at this stage, add things not in the domain model.
University records system class diagram


Inheritance in class diagrams

Inheritance in class diagrams is shown via an open arrow pointing at the superclass, for example:
Inheritance in a class diagram

Use cases

We may return to this in a later week, depending on how you are progressing.

The other step we need to take as an initial analysis and design step is use-case analysis. This takes a different approach to the problem compared to the domain model by considering the system from a user point of view; i.e. thinking about how the user will interact with the system. For example, we consider questions such as:

After performing use-case analysis, we produce a use-case diagram and then (ideally) use-case texts.

An example use case diagram

A use case diagram shows:

Use-case diagram for the university application

Dependencies between use cases

A more detailed use-case diagram will show dependencies between use cases. Dependencies include:

An example is here:
Use case diagram showing dependencies
See diagrams.net: "Draw a UML use case diagram".

Generalised and specialised actors

Use-case texts

The next step is to break down each use case shown on the diagram into a series of steps describing how a user will interact with the system in order to complete the use case. use-case text has two columns:

Example use-case text: Enrol student

Step Actor action System response
1 The use case begins when the admin staff selects to enrol a new student. -
2 - System prompts the user for the student details (name, address, date of birth, course)
3 The user enters the details specified in step 2. -
4 - System checks validity of details, e.g. date of birth is sensible
5 - System allocates student ID for new student
6 - System enrols student in university
7 - System confirms enrolment is successful

Alternative courses of action

Our use-case text must also include alternative courses of action. These describe how the system should react to errors, which can help us design robust systems. These go below the main use-case text. For example, in the previous use-case text:

At step 4: Date of birth is not sensible.
    Staff informed that date of birth is not sensible.
    Staff re-prompted for details (go back to step 3)

Example use-case text: Edit student details

This is a simplified version assuming includes or extends are not being used.

Step Actor action System response
1 The use case begins when the admin staff selects to edit the student details -
2 - System prompts the user for the student ID
3 The member of staff enters the student ID. -
4 - System checks that the student ID exists
5 - System displays details of that student in editable text boxes
6 The admin staff changes the details. -
7 - System checks that the new details are valid (e.g. no blank strings)
8 - System updates details of the student

Alternative courses of action:

At step 4: Student ID does not exist on system 
    Staff informed that the student ID does not exist
    Staff re-prompted for details (go back to step 2)

At step 7: New details are not valid (e.g. blank strings)
    Staff informed that the new details are invalid
    Staff re-prompted for details (go back to step 6)

Drawing the diagrams - diagrams.net

We will be using diagrams.net, an online piece of free software, to draw the diagrams. The labs will start with a live demo of this so please ensure you attend (or if you cannot attend, please ensure you watch the video later). diagrams.net have produced a very useful and extensive blog explaining how to draw different types of diagram. You will probably find the following particularly useful:

Exercise

Look at this problem statement:

There is a requirement for a piece of software to manage bands and bookings for
a live music venue. Customers should be able to view all events, search for and book events, as well as cancel bookings, on the web. Customers can also call the venue to book over the phone: venue staff should also be able to perform these tasks on behalf of customers when they book over the phone. Venue staff should be able to add and cancel events. 
  1. Create a domain model for this problem statement.
  2. Add some likely attributes and methods to the domain model to produce a class diagram.
  3. Before moving onto use cases, ensure you have finished Questions 1-11 of Week 2, and the whole of Week 3. You need all these for the first assignment (the group project).