Classdiagrams
A classdiagram (sometimes referred to as an objectclassdiagram) is used to illustrate classes, class properties (attributes and operations) and associations with other classes.
Before we look at class diagrams in more detail, there are a few fundamental concepts of object technology that we need to discuss.
What is an object?
‘An object is a representation of a real-world thing or event.’ (Kendall and Kendall, 2002)
For example, a person is a real-world object. The computer might store
- the name of the person:John James
- the person’s address:12 Dusky Mews Red Hill
- the person’s phone number:97785643
- the person’s credit card number:4567786756555.
Objects define attribute values such as name and address.
Classes
Objects are grouped into a larger class of objects that have the same attributes and operations. A person might be a member of a class of objects called Student. Hence, an object is an instance of a class. Objects exchange messages, which trigger operations. Operations modify one or more attributes of an object and are declared in a class. An example of an operation might be ‘add’ or ‘update’.
A class is represented as a rectangle with three areas separated by horizontal lines.
The top area holds the class name / Employeename: string
address: string
addEmployee0
The middle area declares all attributes for the class.
The bottom area contains the operations
Associations
An association is the relationship between classes or class instances (objects). For example, a Teacher teaches Subjects or a Subject has Offerings.
The association degree is the number of classes that participate in the association. The three association degrees are binary, unary and ternary.
The following illustrates a binary association between Teacher and Subject:
Image: Diagram demonstrating a binary association between Teacher and Subject
Figure 1: Binary association between teacher and subject
The associationmultiplicity defines the number of objects that can participate in the association. There is minimum and maximum object participation for each association, with an unspecified maximum being shown as an asterisk *. An unspecified minimum need not be specified at all if we know it is more than one.
In the following example, each teacher can teach an unspecified maximum number of subjects as long as his or her weekly hours do not exceed 24 (this is an external constraint set by an industrial award). Teachers may teach 0 subjects if they are involved in non-teaching projects.
Each subject is taught by only one teacher, but it is possible to have subjects that have not yet been assigned a teacher.
Image: Diagram illustrating the association between Teacher and unassigned Subjects
Figure 2: Association multiplicity
Generalisation and inheritance
Generalisation is the concept that some classes are the subclasses of other more general classes. They are represented by a hollow triangle on the relationship end connected to the parent class. One method of representing generalisation is shown below:
Image: Diagram showing the relationship between general classes and their subclasses.
Figure 3: Classes and subclasses
The important point to note with generalisation hierarchies is that the subclass inherits the attributes and operations of its parent class. So the Employee superclass defines all attributes and operations common to Employees and the subclass Faculty, Admin and Maint/ops defines only those attributes and operations specific to the subclass.
Image: Diagram showing the generalisation hierarchies using the class diagram example.
Figure 4: Class diagramhierarchy example
Source: Diploma of Information Technology (Knowledge Management) Toolbox developed by Barrier Reef Institute of TAFE, in consortium with TAFE Qld On-Line
2836_reading5.doc: Determine technical requirements1
© State of New South Wales, Department of Education and Training, 2006