Lab Manual
CPCS 457
Software engineering theory
1433/1434H
Lab – 6
Design Class diagram
Names I.D.
1. .………..………. ………
2. ………. ………
LAB objective:
Overview
Introduction to class diagram
Design class diagrams
How to design a class diagram
Representing Relationships
Class diagram example
Overview
The class diagram is the main building block of object oriented modeling. It is used both for general conceptual modeling of the systematic of the application, and for detailed modeling translating the models into programming code. Class diagrams can also be used for data modeling. The classes in a class diagram represent both the main objects, interactions in the
application and the classes to be programmed.
introduction to class diagram:
class diagram is a type of static structure diagram that describes the structure of a system by showing the system's classes, their
attributes, operations (or methods), and the relationships among the classes.
Class diagram design:
In the diagram, classes are represented with boxes which contain three parts:
The upper part holds the name of the class
The middle part contains the attributes of the class
The bottom part gives the methods or operations the class can take or undertake
How to design a class diagram:
1- Determine which classes require persistent storage
2- Define persistent classes
3- Represent relationships among persistent classes
4- Choose appropriate data types and value restrictions (if necessary) for each field
Representing Relationships Type of relationships
- 1:1, 1:M, M:M (one-to-one, one-to-many, many-to- many)
- Association class used with M:M
One-to-One Relationship Represented with Attributes Containing Object Identifiers
33
Systems Analysis and Design in a Changing World, 4th
One-to-Many Relationship Between Customer and Order Classes
34
Systems Analysis and Design in a Changing World, 4th Edition
One-to-Many Relationship Represented with Attributes Containing Object Identifiers
35
Systems Analysis and Design in a Changing World, 4th Edition
Many-to-Many Relationship Employee and Project Classes
36
Systems Analysis and Design in a Changing World, 4th Edition
Generalization Hierarchy within
the RMO Class Diagram (Figure 12-21)
Class diagram Example:
Example #1: Inheritance – Vehicles
This diagram shows an inheritance hierarchy – a series of classes and their subclasses. Its for an imaginary application that must model different kinds of vehicles such as bicycles, motor bike and cars.
Notes
All Vehicles have some common attributes (speed and colour) and common behaviour (turnLeft, turnRight)
Bicycle and MotorVehicle are both kinds of Vehicle and are therefore shown to inherit from Vehicle. To put this another way, Vehicle is the superclass of both Bicycle and MotorVehicle
In our model MotorVehicles have engines and license plates. Attributes have been added accordingly, along with some behaviour that allows us to examine those attributes
MotorVehicles is the base class of both MotorBike and Car, therefore these classes not only inherit the speed and colour properties from Vehicle, but also the additional attributes and behaviour from MotorVehicle
Both MotorBike and Car have additional attributes and behaviour which arespecific to those kinds of object.
Example #2: Mixed Example – Company, Employee, Manager
This example is from a system that models companies, e.g. for a payroll or reporting system. See if you can interpret it yourself!