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:
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.
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.
We perform an analysis on the problem statement and derive two classes of artefact from it:
The domain model is an initial diagram showing possible classes in the system, and their interaction. We derive it by:
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:
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 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.
Each class is represented by a box, with content as follows:
ACCESS AttributeName: AttributeTypewhere ACCESS is:
ACCESS method(param1: DataType, param2: DataType): ReturnType
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.
Inheritance in class diagrams is shown via an open arrow pointing at the superclass, for example:
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:
A use case diagram shows:
A more detailed use-case diagram will show dependencies between use cases. Dependencies include:
delete a student
might extend search for a student
, because after searching for a student object, the administrator might optionally delete itenrol a student
might include edit student details
, because student details is part of the process of enrolling a studentlogin
use case might precede enrolling a student, updating a student's details, or deleting a studentThe 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:
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 |
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)
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)
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:
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.