Object Oriented Programming Lab 2
Object Oriented Programming Lab 2
Lab No. 02
Lab 02 – Class diagram with their notation and relationships
Class Diagram
Class diagrams are visual representations of the static structure and composition of a particular
system using the conventions set by the Unified Modeling Language (UML).
System designers use class diagrams as a way of simplifying how objects in a system interact
with each other.
Using class diagrams, it is easier to describe all the classes, packages, and interfaces that
constitute a system and how these components are interrelated.
Since class diagrams are used for many different purposes, such as making stakeholders aware
of requirements to highlighting your detailed design, you need to apply a different style in each
circumstance
Example
Simple class diagram may be used to show how an organization such as a convenient store
chain is
set up.
Precisely detailed class diagrams can readily be used as the primary reference for translating
the
designed system into a programming code.
An object is any person, place, thing, concept, event, screen, or report applicable to your
system.
Objects both know things (they have attributes) and they do things (they have methods).
A class is a representation of an object and, in many ways, it is simply a template from which
objects are created.
Classes form the main building blocks of an object-oriented application.
Example
Although thousands of students attend the university, you would only model one class,
called Student, which would represent the entire collection of students.
2. Attributes
An attribute of a class represents a characteristic of a class that is of interest for the user.
3. Operations
A UML operation is a declaration, with a name, parameters, return type, exceptions list, and
possibly a set of constraints of pre and post conditions. But, it isn’t an implementation – rather,
methods are implementation.
4. Visibility:
Use visibility markers to signify who can access the information contained within a class.
Public +
Private -
Protected #
Package ~
Relationship
1. Association
An association is a "using" relationship between two or more objects in which the objects have
their own life time and there is no owner.
For Example: A patient may visit one or many doctors and same way, a doctor can be associated
with multiple patients. If a patient dies, existence of doctor will not be vanished and similarly if
doctor dies patient will remain patient.
Association is represented as thin line connecting two classes. Association can be unidirectional
(shown by arrow at one end) or bidirectional (shown by arrow at both end) or without arrow.
Multiplicity defines how many instances can be associated at any given moment.
Example:
Association Wrote between Professor and Book with association ends author and textbook.
2. Aggregation
Aggregation is a special form of association. It is also a relationship between two classes like association,
however, it’s a directional association, which means it is strictly a one way association, means
unidirectional association. It represents a Has-A relationship.
For Example: Consider two classes Student class and Address class. Each student must have an address
so the relationship between student and address is a Has-A relationship. But if you consider its vice versa
then it would not make sense as an Address doesn’t need to have a Student necessarily.
NOTE: Unarguably, Address is an attribute of a student, but here in this example I am breaking address
into
several fields i.e city, province and country. This is the reason for making address a class.
3. Composition
Composition is a special case of aggregation. In a more specific manner, a restricted aggregation
is called composition. When an object contains the other object, if the contained object cannot
exist without the existence of container object, then it is called composition.
For Example: Consider the same scenario with some modifications. In this scenario, a student has
address and each student has different address (Please keep sibling relationship argument apart).
So, when a student record is added his house number and street number will be entered. And if I
delete the record of a particular student, then his/her record will be of no use.
Example:
4. Generalization
In object oriented programming, the concept of IS-A is a totally based on Inheritance, which can
be of two types Class Inheritance or Interface Inheritance. It is just like saying "A is a B type of
thing". For example, Apple is a Fruit, Car is a Vehicle etc. Inheritance is uni-directional. For
example House is a Building. But Building is not a House.
It is key point to note that you can easily identify the IS-A relationship. Wherever you see an
extends keyword or implements keyword in a class declaration, then this class is said to have IS-
A relationship.
Case Study1
Problem Statement:
The case study titled Library Management System is library management software for the purpose
of monitoring and controlling the transactions in a library. This case study on the library
management system gives us the complete information about the library and the daily transactions
done in a Library. We need to maintain the record of new s and retrieve the details of books
available in the library which mainly focuses on basic operations in a library like adding new
member, new books, and up new information, searching books and members and facility to borrow
and return books. It features a familiar and well thought-out, an attractive user interface, combined
with strong searching, insertion and reporting capabilities. The report generation facility of library
system helps to get a good idea of which are ths borrowed by the members, makes users possible
to generate hard copy.
The following are the brief description on the functions achieved through this case study:
End-Users:
• Librarian: To maintain and update the records and also to cater the needs of the users.
• Reader: Need books to read and also places various requests to the librarian.
Use-case Diagram
Librarian
• Issue a book
• Update and maintain records
• Request the vendor for a book
• Track complaints
User
• Register
• Login
• Search a book
• Request for isse
• View history
Books Database
• Update records
• Show books status
Vendors
• Provide books to the library
• Payment acknowledgement
Sequence Diagram
Sequence diagram for searching a book and issuing it as per the request by the user from the
librarian:
Collaboration Diagram
Collaboration Diagram for searching a book and issuing it as per the request by the user from the
librarian:
Activity Diagram
Activities:
States:
Authentication
Successfully logged on or re-login
Prepared By: Syed CS-121 | Object Oriented 9
Faisal Ali Programming
March 11, 2019 Lab 02 – Class diagram with their notation and relationships .
Search for a book (user) / request the vendor (librarian) / provide the requested book (vendor)
Receive acknowledgement
Logged off / re-search / new function
Transitions:
Component Diagram
Components:
Deployment Diagram
Systems Used:
Local Consoles / Computers for login and search purposes by users, librarian and vendors.
Library LAN Server interconnecting all the systems to the Database.
Internet to provide access to Venodors to supply the requested books by the Librarian
Vendor Server to maintain the records of the requests made by the librarian and books provided
to the library.
Task 1: Create a UML Class diagram of the below scenario also include all possible
relations
Note: Add appropriate attributes and methods according to the order management system
Organizations, projects, team, employee and employee roles in teams. An organization relates to
zero or more projects, zero or more teams and zero or more people who are employee of the
organization. A project related to a single organization and to a single team. A team relates to a
single organization to a single project. A person relates to a single organization that is an employer.
A team relates to a zero or more people as member of the team in which a person plays a role. A
person relates to a single team in which a person plays a role.
A project has name that is a string, a start and end date that are strings, a budget that is a real
number and an operation to ensure that the start date and end date of a project are valid. Each team
and organization has a name that is a string. A person has an identification number that is an
integer, a name that is string, hours that they are available to work, and an operation to determine
whether the number of hours that they are available to work, and an operation to determine whether
the number of hours that they are available to work is within the range of minimum and maximum
number of hours. The relationship between a person and a team defines the title as a string of the
role that the person plays on the team. All the attributes and operations are public, but a project’s
start date, end date and the hours they are available to work are private
Task 3 Create a UML Class diagram of the given School Management System.
Task 4: Analyze the Hotel Management System for Holiday Inn Hotel which is well known
international hotel. Your task is to analyze the complete system, write them according to your
analysis. Make all the diagrams as discusses in Case Study 1.