You are on page 1of 17

Lecture 1 - Class Diagrams

Ralph Tambala

MUST . CSIT

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 1 / 17


Outline

1 Overview
2 Class Diagram
Names
Attributes
Operations
3 Class Relationships
Association
Aggregation
Generalization
4 Practice Work
5 Additional Resources

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 2 / 17


Overview

Overview
1 The goal of this lecture is to cover the basics of designing Class
Diagrams using UML.
2 Everything that is not point 1 is not within the scope of this lecture.
3 Go to point 1. // its an infinite loop

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 3 / 17


Class Diagram

Class Diagram
Class diagrams are the main building block in object-oriented
modeling. They are used to show the different objects in a system,
their attributes, their operations and the relationships among them.
A class is represented graphically as a rectangle, with its name,
attributes, and operations separated into distinct compartments.
Class diagrams help to construct the code for the software application
development.

Figure 1: Skeleton of a Class Diagram


Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 4 / 17
Class Diagram Names

Class Names

In a graphical representation of a class, the name of the class is the


only necessary tag. It always appears in the top-most compartment.

Figure 2: Class with name Student

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 5 / 17


Class Diagram Attributes

Class Attributes
An attribute is a named property of a class that describes the object
being modeled. In the class diagram, attributes appear in the second
compartment just below the class name compartment.

Figure 3: Student class attributes

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 6 / 17


Class Diagram Attributes

Class Attributes cont...(2)


Attributes are usually listed in the form:
attributeName : Type
A derived attribute is one that can be computed from other
attributes, but doesn’t actually exist. For example, a Person’s age can
be computed from his\her date of birth. A derived attribute is
designated by a preceding forward slash ‘/’ as shown below:
/ age : Date

Figure 4: Person class attributes

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 7 / 17


Class Diagram Operations

Class Operations
Operations describe the class behaviuor and appear in the third
segment. These are services the class provides.

Figure 5: Person class operations/methods

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 8 / 17


Class Diagram Operations

Different Ways of Depicting Classes

Sometimes a class can be drawn without its attributes and operations.

Figure 6: Different representations of Student class

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 9 / 17


Class Diagram Operations

Visibility of Attributes and Operations


Class attributes and operations can also be represented using their access
specifiers (visibility).

Figure 7: Summary of visibilities

Figure 8: An example showing visibility - Customer class


Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 10 / 17
Class Relationships

Class Relationships
There are three basic categories of class relationships:
Association
Aggregation
Generalization

Figure 9: Different depictions of class Student


Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 11 / 17
Class Relationships Association

Association

The term ”association” refers to any conceptual connection or relationship


that exists between classes. For example, passenger and airline may be
linked as shown in Figure 10.

Figure 10: Association

Association can also show cardinality of a class in relation to another. This


is called multiplicity. For example, one fleet may include multiple
airplanes, while one commercial airplane may contain zero to many
passengers.

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 12 / 17


Class Relationships Aggregation

Aggregation
Aggregation refers to the formation of a particular class as a result of one
class being aggregated or built as a collection. For example, the class
Library is made up of one or more books, among other materials. It is a
special type of association. It represents a “part of” relationship. In
aggregation, the contained classes are not strongly dependent on the
lifecycle of the container. For example in in Figure 11, class Book will
remain so even when the class Library is dissolved.

Figure 11: Association

To show aggregation in a diagram, draw a line from the parent class to the
child class with a diamond shape near the parent class. What of
Composition?
Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 13 / 17
Class Relationships Generalization

Generalization/Inheritance
Generalization or inheritance refers to a relationship in which one
associated class becomes a member of another by inheriting the parent
class’ functionalities. It represents an “is-a” relationship. In other words,
the child class is a subset of the parent class.

Figure 12: Generalization

To show inheritance in a UML diagram, a solid line from the child class to
the parent class is drawn using an unfilled arrowhead as in Figure 12.
Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 14 / 17
Practice Work

Practice Work

Consider the following University system:


In a university, there are different classrooms, offices and
departments. A department has a name and it contains many offices.
A person working at the university has a unique ID and can be a
researcher, lecturer or a support staff.
A researcher can be a full, associate or assistant researcher and
he/she is member in one department.
Offices and classrooms have a number ID, and a classroom has a
number of seats.
A lecturer teaches in one or more classrooms and he/she is member
in one department.
Every support staff works in an office.

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 15 / 17


Practice Work

Practice Work cont...(2)

1 What classes are in this system?


2 What are their attributes and operations?
3 State class relationshps in this system.
4 Draw a class diagram for this system. Include relationships between
classes (generalization and association).

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 16 / 17


Additional Resources

Additional Resources/Info

1 Post solutions of your practice work in the forum. Don’t be shy!


Scanned handwritten work is also acceptable for this exercise.
2 You may find this book useful for an in-depth read: System Analysis
and Design - An Object-Oriented Approach with UML by Dennis,
Wixon, and Tergaden.
3 Next class, we will start coding. By then make sure you at least know
how to write, compile and run a “helloworld” program in Java.

Ralph Tambala (MUST . CSIT) Lecture 1 - Class Diagrams 17 / 17

You might also like