Class diagrams -Introduction

Class – A set of related items or objects which share common attributes and methods.

A class diagram shows how classes will interact with one another. Classes very rarely will work on their own but work as part of a system. Only the smallest of systems would only use one class. One of the main focuses on object orientated design is encapsulation -

Encapsulation is where a class will hide the inner workings and allow calling classes a interface which does not need detailed knowledge of that class in order to use it.

Encapsulation leads to splitting up of roles in a problem. You should read the section on OO design to see how this can be done. Here we are going to assume you know how and why we do it!

A class will be split into 3 sections as shown in the diagram below -

 

The attributes will have a data type and this is specified after the attribute name. For example a: int means we have a variable called “a” which has the data type of int. Method use the same terminology so in this case the method “doStuff” has a single parameter called “a” of data type int. It then will return a int which again is specified after the method name. UML always specify the data type after the name.