You are on page 1of 32

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING


DEPARTMENT OF COMPUTER ENGINEERING

CAED

UML (Class Diagram)

Lab Manual 15

Dated:
st th
4 December, 2023 to 8 December, 2023

Semester:
FALL 2023

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Lab Instructions
1. All Students should reach at lab on time.
2. Students should sit on the same computer during whole semester.
3. Student should make a directory by his/her name and store all his/her data in it.
4. Student could take the backup of his/her program the instructor permission.
5. Record Instructions: 1. Lab copy should be updated. 2. Lab copy should be checked on each lab.
Lab Objective:
Understand what is UML?, What are its goals?, Different types different UML diagrams and their usage.
How to add Notes and Constraints in UML?, Understand concepts of “Association” and “Relationship”
between classes, How to represent associations in UML?.
Understand concepts of “Relationship” between different classes and a class itself, Understand
“Generalization” in UML, How to represent these things in UML?.
Understand “Association classes, Links, Aggregation and Composition” in UML, How to represent
these things in UML?
Tools:
MS Visio, E-draw
UML:
UML is a standard language for specifying, visualizing, constructing, and documenting the artifacts
of software systems.
 UML stands for Unified Modelling Language.
 UML is different from the other common programming languages like C++, Java, COBOL
etc.
 UML is a pictorial language used to make software blue prints.
So UML can be described as a general purpose visual modelling language to visualize, specify,
construct and document software system.

 UML has a direct relation with object oriented analysis and design.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Goals of UML:

 A picture is worth a thousand words, this absolutely fits while discussing about UML. There
are a number of goals for developing UML but the most important is to define some general
purpose modelling language which all modelers can use and also it needs to be made simple
to understand and use.

 UML diagrams are not only made for developers but also for business users, common people
and anybody interested to understand the system. The system can be a software or non-
software. So it must be clear that UML is not a development method rather it accompanies
with processes to make a successful system.

 At the conclusion the goal of UML can be defined as a simple modelling mechanism to
model all possible practical systems in today’s complex environment.
A Conceptual model of UML:
To understand conceptual model of UML first we need to clarify: What is a conceptual model? and
why a conceptual model is at all required?
 A conceptual model can be defined as a model which is made of concepts and their
relationships. A conceptual model is the first step before drawing a UML diagram. It helps
to understand the entities in the real world and how they interact with each other.
As UML describes the real time systems it is very important to make a conceptual model and then
proceed gradually. Conceptual model of UML can be mastered by learning the following three
major elements:
 UML building blocks
 Rules to connect the building blocks
 Common mechanisms of UML

Object Oriented concepts:


Objects concrete and otherwise, are all around us. They make up our world. First and foremost, an
object is an instance of a class (a category). You and I, for example, are instances of the Person
class. An object has structure. That is, it has attributes (properties) and behavior. An object's
CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa
Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
behavior consists of the operations it carries out. Attributes and operations taken together are called
features. An object contains both data and methods that control the data. The data represents the
state of the object.
The objects are the real world entities that exist around us and the basic concepts like
abstraction, encapsulation, inheritance, polymorphism all can be represented using UML. So UML
is powerful enough to represent all the concepts exists in object oriented analysis and design. UML
diagrams are representation of object oriented concepts only. So before learning UML, it becomes
important to understand OO concepts in details.
Following are some fundamental concepts of object oriented world:

 Class: Class is an entity, a template for making objects, a collection of things that share
some common features.
 Object: Object represent an instance of a single entity/class.
 Abstraction: It means, simply, to filter out an object's properties and operations until just the
ones you need are left.
 Encapsulation: Encapsulation is the mechanism of hiding data from outside world.
 Association: When classes are connected together conceptually.
 Composition: When an object is composed of another object.
 Inheritance: Inheritance is the mechanism of making new classes from existing one.
 Polymorphism: It defines the mechanism to exist in different forms.
 Interface: Implemented by multiple classes.

UML Diagrams:
There are two broad categories of diagrams and then are again divided into sub-categories:
1. Structural Diagrams
2. Behavioral Diagrams

The structural diagrams represent the static aspect of the system. These static aspects represent
those parts of a diagram which forms the main structure and therefore stable.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
These static parts are represents by classes, interfaces, objects, components and nodes.
The four structural diagrams in UML are:
 Class diagram
 Object diagram
 Component diagram
 Deployment diagram

Behavioral diagrams basically capture the dynamic aspect of a system. Dynamic aspect can be
further described as the changing/moving parts of a system.
UML has the following five types of behavioral diagrams:
 Use case diagram
 Sequence diagram
 Collaboration diagram
 Activity diagram
UML Class Diagram

The class diagram is a static diagram. It represents the static view of an application. The class
diagram describes the attributes and operations of a class and also the constraints imposed on the
system.
Purpose:
The cla’ss diagrams are widely used in the modelling of object oriented systems because they are
the only UML diagrams which can be mapped directly with object oriented languages.

How to draw Class Diagram?


Class diagram is basically a graphical representation of the static view of the system and
represents different aspects of the application. So a collection of class diagrams represent the whole
system.
The following points should be remembered while drawing a class diagram:
 The name of the class diagram should be meaningful to describe the aspect of the system.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
 The name of a class begins with an uppercase letter.
 A multiword class name runs all the words together, and each word begins with an uppercase
letter for the first one.
 The name of a feature (attribute or operation) begins with a lowercase letter.
 A multiword feature name runs all the words together, and each word begins with an
uppercase letter except for the first one.
 A pair of parentheses follows the name of an operation.
 Responsibility (attributes and methods) of each class should be clearly identified.
 Use notes whenever required to describe some aspect of the diagram. Because at the end of
the drawing it should be understandable to the developer/coder.

As objects in the Person class, you and I each have these attributes: height, weight, and age.
(You can imagine a number of others.) Each of us is unique because of the specific values that each
of us has for those attributes. We also perform these operations: eat, sleep, read, write, talk, go to
work, and more (Or in object speak, eat(), sleep(), read(), write(), talk(), and goToWork()).
The pieces of information about an operation are called the operation's signature.
Example of a Class diagram:
Let’s take an example of a washing machine.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

The class icon enables you to specify still another type of information about a class. In an
area below the operations list, you can show the class's responsibility. The responsibility is a
description of what the class has to do—that is, what its attributes and operations are trying to
accomplish. A washing machine, for example, has the responsibility of taking dirty clothes as input
and producing clean clothes as output.

Object diagram for Washing Machine:

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Case Study #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

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
 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.
Case Study #2: Relationships – Students and Courses
This example demonstrates relationships between classes. It’s from an imaginary application that
models university courses.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Notes
 Each Course object maintains a list of the students on that course and the lecturer who has
been assigned to teach that course
 The Course object has behavior that allow the adding and removing of students from the
course, assigning a teacher, getting a list of the currently assigned students, and the currently
assigned teacher.

 Teachers are modelled as Lecturer objects. As a lecturer may teach more than one course
there is an association between Course and Lecturer. The “taughtBy” relationship shows that
a Course only has a single teacher, but that a lecturer may teach several Courses.
 Each Lecturer object also maintains a list of the Courses that it teaches.
 There is a similar relationship between Course and Student. A course is attended by zero
or more Students, and a Student may attend multiple courses.
This example also demonstrates the use of interfaces. The diagram shows a Person interface that
stipulates that objects conforming to this interface will have a getName and getEmailAddress
methods. Both Lecturer and Student are shown to be types of Person.
Case Study #3: 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!

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Example of a class diagram for Washing Machine:

The class icon enables you to specify still another type of information about a class. In an
area below the operations list, you can show the class's responsibility. The responsibility is a
description of what the class has to do—that is, what its attributes and operations are trying to
accomplish. A washing machine, for example, has the responsibility of taking dirty clothes as input
and producing clean clothes as output.

Some other features


The UML provides features that enable you to extend the diagrams.
 Notes:
It often happens that one part of a diagram doesn't present a clear explanation of why it's
there or how to work with it. When that is the case, the UML note is helpful. Think of a note as the
graphic equivalent of a yellow sticky. Its icon is a rectangle with a folded corner. Inside the
rectangle is explanatory text. Figure below shows an example. You attach the note to a diagram
element by connecting a dashed line from the element to the note.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

 Constraints:
UML provides facility to add constraints on a class attributes or properties. Constraint is
added as a free-form text enclosed in curly brackets. The bracketed text specifies one or more rules
the class follows. For example, suppose in the WashingMachine class you wanted to specify that the
capacity of a washer can be only 16, 18, or 20 pounds (and thus "constrain" the WashingMachine
class's capacity attribute). You would write {capacity = 16 or 18 or 20 lbs} near the
WashingMachine class icon.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
 Keywords and Stereotypes:
Stereotypes enable you to create new UML elements by basing them on existing elements.
It's sort of like buying a suit off the rack and having it altered to fit your particular measurements (as
opposed to creating one out of a bolt of cloth). Think of a stereotype as just this kind of alteration.
You represent it as a name enclosed in two pairs of angle brackets called guillemets, and then you
add that name to a UML symbol. The guillemet-enclosed name is called a keyword.

Conceptual modeling in UML:


To understand conceptual model of UML first we need to clarify:
 What is a conceptual model?
 Why a conceptual model is at all required?

A conceptual model can be defined as a model which is made of concepts and their
relationships. A conceptual model is the first step before drawing a UML diagram. It helps to
understand the entities in the real world and how they interact with each other. As UML describes
the real time systems, it is very important to make a conceptual model and then proceed gradually.

Relationships in Class Diagrams:

Classes are interrelated to each other in specific ways. In particular, relationships in class diagrams
include different types of logical connections. The following are such types of logical connections
that are possible in UML:

 Association

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

 Directed Association
 Reflexive Association
 Multiplicity
 Inheritance/Generalization
 Aggregation
 Composition
 Realization

Associations:
When classes are connected together conceptually, that connection is called an association.
Association can be uni-directional or bi-directional.
Uni-directional: A Car “contains” Wheel but Wheel does not contain Car.
Bi-directional: A Boy is married to a Girl.

Associations in UML
Let's examine one—the association between a player and a team. You can characterize this
association with the phrase "a player plays for a team." You visualize the association as a line
connecting the two classes, with the name of the association ("Plays for") just above the line. You
show how to read the relationship with a filled triangle pointing in the appropriate direction.

When on class associates with another, each one plays a role with that association. You can
show each class’s role by writing it near the line next to the class. In association between a team and
a player, a team is usually and employer and the player is employee.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

You can imagine an association that you could read in the other direction: A team employs
players. You can show both associations in the same diagram, with a filled triangle indicating how
to read each association.

Multiplicity:
Multiplicity is an important aspect of associations among objects. It tells the number of
objects in one class that relate to a single object of the associated class. For example, in a typical
college course, the course is taught by a single instructor. The course and the instructor are in a one-
to-one association.
In UML, a variety of multiplicities are possible. One class can relate to another class in
different ways as following:
 1-to-1
 1-to-many
 many-to-many
 1-to-“1 or more” (also called “Mandatory” relationship)
 1-to-“0 or one” (also called “Optional” relationship)
 1-to-a bounded interval (e.g. 1-to-5 through 10)
 1-to-exactly ‘n’
 1-to-a set of choices (e.g. 1-to-“9 or 10”)

UML uses an asterisk (*) to represent more/many. In one context ‘or’ is represented as two
dots, for example 1..* (“one or more”). In other context, “or” is represented by a comma (,) e.g. 5,10
(“5 or 10”).

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Multiplicity Meanings
1 Exactly one instance
* Many instances
0..1 No instances or one instance

0,1 No instances or one instance


0..* Zero or more instances
1..* One or more/At least one instance
5 Exactly 5 instances
m..n At least m but no more than n instances
m,n Exactly m or n

Here are a few examples of UML multiplicities:

 A Customer can place zero or more Orders.

 A Tricycle has exactly 3 wheels.

 An EggBox may hold one or two dozen eggs.

 This is a complete example of representing association in both ways. A Professor can write zero or many
Books and a Book is written by at least one author. There can be more than one authors for a Book.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Conceptual modeling in UML:
To understand conceptual model of UML first we need to clarify:
 What is a conceptual model?
 Why a conceptual model is at all required?

A conceptual model can be defined as a model which is made of concepts and their
relationships. A conceptual model is the first step before drawing a UML diagram. It helps to
understand the entities in the real world and how they interact with each other.

Relationships in Class Diagrams:

In particular, relationships in class diagrams include different types of logical connections. The
following are such types of logical connections that are possible in UML:

 Association
 Directed Association
 Reflexive Association
 Multiplicity
 Inheritance/Generalization
 Aggregation
 Composition
 Realization

Associations:
When classes are connected together conceptually, that connection is called an association.
Association can be uni-directional or bi-directional.
Associations in UML:
In Lab 02, we have learnt how to create Associations between different classes and how to

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
represent them in UML. Let's examine one—the association between a player and a team. You can
imagine an association that you could read in the other direction: A team employs players. You can
show both associations in the same diagram, with a filled triangle indicating how to read each
association.

Multiplicity:
Multiplicity tells the number of objects in one class that relate to a single object of the
associated class. In UML, a variety of multiplicities are possible. One class can relate to another
class in different ways as following:
 1-to-1, 1-to-many, many-to-many, 1-to-“1 or more” (also called “Mandatory” relationship),
1-to-“0 or one” (also called “Optional” relationship), 1-to-a bounded interval (e.g. 1-to-5
through 10), 1-to-exactly ‘n’, 1-to-a set of choices (e.g. 1-to-“9 or 10”).

Multiplicity Meanings
1 Exactly one instance

* Many instances

0..1 No instances or one instance

0,1 No instances or one instance

0..* Zero or more instances

1..* One or more/At least one instance

5 Exactly 5 instances

m..n At least m but no more than n instances

m,n Exactly m or n

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
 This is a complete example of representing association in both ways. A Professor can write zero
or many Books and a Book is written by at least one author. There can be more than one
authors for a Book.

Qualified Associations:

When an association's multiplicity is one-to-many, a particular challenge often arises:


lookup. When an object from one class has to choose a particular object from another in order to
fulfill a role in an association, the first class has to rely on a specific attribute to select the correct
object. That attribute is typically an identifier, such as an ID number. For example, a hotel's
reservation list has many reservations.

When you make a reservation at a hotel, the hotel assigns you a confirmation number. If you call
with questions about the reservation, you have to supply the confirmation number, so that someone
looking through the reservation list can select your reservation.
In the UML, the ID information is called a qualifier. Its symbol is a small rectangle
adjoining the class that has “one” part in the one-to-any multiplicity. Although the reservation
between ReservationList and Reservation is one-to-many, the multiplicity between
confirmationNumber and Reservation is one-to-one.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Reflexive Associations:
Sometimes, a class is in an association with itself. Referred to as a reflexive association, this can
happen when a class has objects that play a variety of roles. For example, a CarOccupant can be
either a driver or a passenger. In the role of the driver, one CarOccupant drives zero or more
additional CarOccupants who play the role of passenger.
You represent this by drawing an association line from the class rectangle back to the same
class rectangle, and on the association line you indicate the roles, name of the association, direction
of the association, and multiplicity as before.

 Associations may be more complex than just one class connected to another. Several classes can
connect to one class. If you consider guards, forwards, and centers, and their associations with
the Team class, you'll have the diagram in figure below.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Constraints on Associations

 Sometimes an association between two classes has to follow a rule. You indicate that rule by
putting a constraint near the association line. For example, a Bank Teller serves a Customer, but
each Customer is served in the order in which he or she appears in line. You capture this in the
model by putting the word ordered inside curly brackets (to indicate the constraint) near the
Customer class, as in figure.

 Another type of constraint is the Or relationship, signified by {or} on a dashed line that connects
two association lines. Figure models a high school student choosing either an academic course of
study or a commercial one.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Inheritance and Generalization
In our daily life, if you know something about a category of things, you automatically know
some information you can transfer to other categories. If you know something is an appliance, you
already know it has an on-off switch, a brand name, and a serial number. If you know something is
an animal, you take for granted that it eats, sleeps, has a way of being born, has a way of getting
from one place to another, and probably has a number of other attributes (and operations) you could
list if you thought about it for a few minutes.

Object-orientation refers to this as inheritance. The UML also refers to this as generalization. One
class (the child class or subclass) inherits attributes and operations from another (the parent class or
superclass). The parent class is more general than the child class.
The inheritance hierarchy doesn't have to end at two levels: A child class can be a parent class for
still another child class. Mammal is a child class of Animal, and Horse is a child class of Mammal.

In the UML, you represent inheritance with a line that connects the parent class to the child
class. On the part of the line that connects to the parent class, you put an open triangle that points to
the parent class. This type of connection stands for the phrase is a kind of. A Mammal is a kind of
Animal, and a Horse is a kind of Mammal.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Dependencies:
In a different kind of relationship, one class uses another. This is called a dependency. The most
common usage of a dependency is to show that the signature of one class's operation uses another
class.

Suppose you're designing a system that displays corporate forms on-screen so employees can
fill them out. The employee uses a menu to select the form to fill out. In your design, you have a
System class and a Form class. Among its many operations, the System class has
displayForm(f:Form). The form the system displays obviously depends on which form the user
selects. The UML notation for this is a dashed line with an arrowhead pointing at the class depended
on.
This figure below shows how to represent a dependency in UML. The class Form depends
on the method displayForm(f:Form) of class System.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Relationships in Class Diagrams:

In particular, relationships in class diagrams include different types of logical connections. The
following are such types of logical connections that are possible in UML:

 Association
 Directed Association
 Reflexive Association
 Multiplicity
 Inheritance/Generalization
 Aggregation
 Composition
 Realization

Association Classes
An association can have attributes and operations, just like a class. In fact, when this is the
case, you have an association class. You visualize an association class the same way you show a
regular class, and you use a dashed line to connect it to the association line. An association class can
have associations to other classes. Figure shows an association class for the Plays on association
between a player and a team. The association class, Contract is associated with the GeneralManager
class.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

 Similarly another example cab be an association “orders” between a Customer and a


Product. Order can have its own attributes and operations, hence we can have an
association class Order.

Link

Just as an object is an instance of a class, an association has instances as well. Link is an


instance of an association. If you imagine a specific player who plays for a specific team, the Plays
on relationship is called a link, and you represent it as a line connecting two objects. Just as you
would underline the name of an object, you underline the name of a link. Link is rendered using the
same notation as for an association. Solid line connects instances rather than classes. End names
(roles) and navigation arrows can be shown.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Aggregations
Sometimes a class consists of a number of component classes. This is a special type of
relationship called an aggregation. The components and the class they constitute are in a part-
whole association. Your home computer system is an aggregation that consists of a CPU box, a
keyboard, a mouse, a monitor, a CD-ROM drive, one or more hard drives, a modem, a disk drive, a
printer, and possibly some speakers.
You represent an aggregation as a hierarchy with the "whole" class (for instance, the
computer system) at the top and the components below. A line joins a whole to a component, with
an open diamond on the line near the whole. Figure below shows the computer system as an
aggregation.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Constraints on Aggregation:

Sometimes the set of possible components in an aggregation falls into an Or relationship.


For example, In some restaurants, a meal consists of soup or salad. To model this, you would use a
constraint-the word or within curly brackets on a dotted line that connects the two part-whole lines,
as figure shows.

Compositions:
A composite is a strong type of aggregation. Each component in a composite can belong to just one
whole. The components of a coffee table—the tabletop and the legs—make up a composite. The
symbol for a composite is the same as the symbol for an aggregation except the diamond is filled, as
shown in figure.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Difference between Composition and Aggregation ???

Composite Structure Diagram

The composite is one way to show the components of a class. If you want to give the sense
of showing the class's internal structure, you can go with the UML composite structure diagram.

Here's an example. Suppose you're creating a model of a shirt. Figure below shows the shirt
as a large class rectangle with its components nested inside. The nested diagram shows how the
components of the shirt relate to one another. The composite structure diagram focuses attention on
the shirt and its internal components.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Lab Task:
 For each of the following pairs of related entities, indicate whether there is any association
between them or not? Then, using the UML notation introduced in the lab, draw a diagram
for association among each pair.
a. DEPARTMENT and HOD
b. BOOK and BOOK COPY (books have copies)
c. ALBUM and PICTURE (Albums contain pictures)
d. LECTURE and ROOM (lectures are scheduled in rooms)
e. VEHICLE and BRAKE (Vehicles have brakes)

 We want to design UMS i.e. University Management System. Possible entities for such a
system can be University, Department, Student, Teacher and Course. Draw class
diagrams and Object for each of these entities and connect these classes with each other
using associations/relationships.

 Draw a model consisting of class diagrams (no need to write attributes or operations for
classes) and relationship between them for a Hospital Management System.

 Identify different entities/classes required for a Pizza Delivery System. Draw class
diagrams, associations and object diagram between different classes if exist.

 Draw class diagrams for an On-line Shopping system (a system where a visitor can visit
any online-shopping site for buying required needs).

 Draw class diagrams (including attributes and operations) and qualified associations if
exist, for the following pair of entities:
o Student and Registration List
o Order and Order Line
o and Product Catalog
o Bank Account and Customer
 Possible entities for a University Management System are University, Department, Student,
Teacher and Course. Identify different attributes, operations and sub-classes/parent classes
(if exist) for each of these entities. Draw class diagrams, show inheritance among different
CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa
Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
entities/classes and object diagram. Identify associations/relationships and their multiplicities
between different classes. Remember, an association with a parent class will be inherited by
all child classes. If you want to associate a relationship with a particular child class only,
then draw association with that child class only.
 For each of the following pairs of related entities, indicate whether there exists any
association class between them or not? Then, using the UML notation introduced in the lab,
draw a diagram for association among each pair.
o Customer and Product
o Student and Course
o Supplier and Item
o Driver and Car
 Draw a UML class diagram for a Vehicle showing aggregation/composition/inheritance
relationship between different components.
 Draw a UML inheritance diagram for a Cricket Team Management including players. You
have to identify different sub-classes/parent classes, their attributes and operations which are
required for managing a cricket team.

CAED Session:-2K22 Computer Lab Instructor:-Adnan Mustafa


Engineering

You might also like