Class Diagrams

A Class diagram (sometimes referred to as an Object Class Diagram) 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 persons address, 12 Dusky Mews Red Hill, the persons phone number, 97785643 and the persons credit card number, 4567786756555.  Objects define attribute values such as name and address etc. 

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'.

employeeA class is represented as a rectangle with three areas separated by horizontal lines. 

^ top

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 

teachers and subjects relationship

The association multiplicity 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/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. 

teacher and subject relationship

^ top

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.

employee

 

The important point to note with generalisation hierarchies is that the subclass inherits the attributes and operations of its parent class.  So that 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.

A Class Diagram Example

class diagram example

This page was sourced from the Diploma of Information Technology (Knowledge Management) Toolbox developed by Barrier Reef Institute of TAFE, in consortium with TAFE Qld On-Line

< back to Object Oriented Analysis

^ top