Professional Documents
Culture Documents
Fall 2022
Class
• A class is the construction plan for a set of similar objects that appear in the
system to be specified.
• Classes can characterize, for example, persons (e.g., students), things (e.g.,
buildings), events (e.g., courses or exams) Examples
Employee: has a name, employee # and
department; an employee is hired, and fired;
an employee works in one or more projects
Employee
name Name (mandatory)
Attributes
(optional) employee#
department
hire()
fire() Operations
assignproject() (optional)
Visibility
Visibility can be:
Attribute
Syntax of attribute
• Operations
• Operations are characterized by their name, their parameters, and the
Operation type of their return value
• + isRegistered (c: Course) :
Boolean
•
Relationships in Class Diagram
In UML, object interconnections (logical or physical), are
modeled as relationships.
1. Dependencies
2. Associations
3. generalizations / specialization
4. Aggregation / Composition
1. Dependency Relationships
A dependency indicates a semantic relationship between two or more elements. The
dependency from CourseSchedule to Course exists because Course is used in both the
add and remove operations of CourseSchedule.
Dependency is represented by a dashed arrow starting from the dependent class to its
dependency. Multiplicity normally doesn’t make sense on a Dependency
CourseSchedule
Course
add(c : Course)
remove(c : Course)
Dependency - A change in a class affects the change in it's dependent class.
Shapes
Example- Circle is dependent on Shape. If you change
Shape, it affects Circle too. So, Circle has a dependency calArea(c: circle)
Circle
on Shape.
2. Association
• Associations represent possible relationships between the instance of classes.
• They describe which classes are potential communication partners
• Also called using relationship between two or more objects
• Representing with a thin line connecting two classes
• The edge can be labeled with the name of the association optionally followed by the reading
direction, a small, black triangle
Example : A patient may visit one or many doctors, similarly a doctor meet multiple patients
( if a patient died, the existence of doctor will not vanished and in the same way if doctor dies patient will
remain patient )
Example :
The classes Professor and Student are related via the association givesLectureFor (as label). In the role as a
lecturer, a professor has zero or more students and one student has zero or more professors in the role of
lecturer.
Association Contd.
• A Company has no, one, or multiple Person and that an Person is
associated with exactly one Company.
1 * .. 0
Company Person
Student
Generalization/Specialization
• Generalization hierarchies may be created by generalizing from
specific things or by specializing from general things.
Parent
More general element
Superclass
Ancestor
Base Class
“is a kind of”
Child
Subclass
Descendant
More specific element
Leaf
Example (Association and Generalization)
• An Order Management System describes a particular aspect of the entire
application.
• First of all, Order and Customer are identified as the two elements of the
system. They have a one-to-many relationship because a customer can have
multiple orders.
• Order class is an abstract class and it has two concrete classes (inheritance
relationship) SpecialOrder and NormalOrder.
• The two inherited classes have all the properties as the Order class. In
addition, they have additional functions like dispatch () and receive ().
Order Management System
Aggregation
• An aggregation is a special form of association that is used to express that
instances of one class are parts of an instance of another class.
• Represented by a hollow diamond at the association end of the class that
stands for the “whole”
• Aggregation is weak relationship
• Also called “is part of“ and in other hand “made of” or “Whole”
• Implies a relationship where the child can exist independently of the parent.
• Example: Lecture (parent) and Student (child). Delete the Lecture and the Students still exist.
• Example: Car (parent) and Engine / Wheel(child)
Engine
Car
Wheels
Composition
• Composition is a specialized form of aggregation in which if the parent object
is destroyed
• It is actually a strong type of aggregation and is also referred to as a "death"
relationship.
• Where the child class cannot exist independent of the parent class
• Compositions are denoted by a filled-diamond
• As an example, a house is composed of one or more rooms. If the house is destroyed,
all the rooms that are part of the house are also destroyed as they cannot exist by
themselves.
• Window and its composite objects File Folder
Scrollbar
1 1
Window Titlebar
1 1
Menu
1 1.
A Big Picture!!
Example - Information system of a university
1. Identifying the classes
A university consists of multiple faculties which are composed of 2. Identifying the attributes
various institutes. Each faculty and each institute has a name. An
address is known for each institute. 3. Identifying the relationships
between classes
Each faculty is led by a dean, who is an employee of the university.
The total number of employees is known. Employees have a social Identified classes
security number, a name, and an e-mail address. There is a
distinction between research and administrative personnel.
• example, imagine the relationship between a doctor and a patient. A doctor can be
associated with multiple patients and at the same time, one patient can visit multiple
doctors for treatment and/or consultation. Each of these objects have their own life-
cycle and there is no owner. In other words, the objects that are part of the association
relationship can be created and destroyed independently.
Summary - Association / Aggregation / Composition
• example of Department and teacher. A single teacher can not belong to multiple
departments, but if we delete the department, the teacher object will not be destroyed
Note a whole can contain a part but the reverse is not true.
Summary - Association / Aggregation / Composition
• Composition is again specialized form of Aggregation and we can call this as a
“strong” relationship. It is a strong type of Aggregation. Child object does not
have its lifecycle and if parent object is deleted, all child objects will also be
deleted.
• example of relationship between House and Rooms. House can contain multiple rooms
- there is no independent life of room and any room can not belong to two different
houses. If we delete the house - room will automatically be deleted..
• example relationship between Questions and Options. Single questions can have
multiple options and option can not belong to multiple questions. If we delete the
questions, options will automatically be deleted
• Product catalog contain product specification
• Product catalog used by store
• Items described by exactly one product description
• Items stokes in exactly one store but store has many items
• Items contained in sale, sale has at leats one item but one item is in
exactly one sale
• A sale is initiated by exactly one customer and a customers
• Sale has payment information (sale has exactly on payment detail and
vise versa)
Home Heating System
• Room has 1 Thermostat
• Each Thermostat is associated with
0 or more Heaters
• A Heather has exactly one
Thermostat
• ElectricHeater is a specialized Heater
• AubeTH101D is a specialized
Thermostat
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
professor or an employee. A professor can be a full, associate or
assistant professor and he/she is enrolled in one department.
• Offices and classrooms have a number ID, and a classroom has a
number of seats.
• Every employee works in an office.
Movie- Shop