OOSE - Week 6 - Class Diagram

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 23

Static Modeling using the

Unified Modeling Language (UML)

Material based on
[Booch99, Rambaugh99, Jacobson99, Fowler97, Brown99]
Software Design (UML)

SERG

Overview of UML Diagrams


Structural
: element of spec. irrespective of time

Class
Component
Deployment
Object
Composite structure
Package

Behavioral
: behavioral features of a system / business
process

Activity
State machine
Use case
Interaction

Interaction
: emphasize object interaction

Communication(collabe
ration)
Sequence
Interaction overview
Timing
SERG

Classes
ClassName
attributes
operations

A class is a description of a set of


objects that share the same attributes,
operations, relationships, and semantics.
Graphically, a class is rendered as a
rectangle, usually including its name,
attributes, and operations in separate,
designated compartments.

Software Design (UML)

SERG

Class Names
ClassName
attributes

The name of the class is the only required


tag in the graphical representation of a
class. It always appears in the top-most
compartment.

operations

Software Design (UML)

SERG

Class Attributes
Person
name
: String
address : Address
birthdate : Date
ssn
: Id

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
name-compartment.
Attributes are usually listed in the
form:
attributeName : Type

Software Design (UML)

SERG

Class Attributes (Contd)


Person
+ name
: String
# address : Address
# birthdate : Date
/ age
: Date
- ssn
: Id

Attributes can be:


+ public
# protected
- private
/ derived

Software Design (UML)

SERG

Class Operations
Person
name
: String
address : Address
birthdate : Date
ssn
: Id
eat
sleep
work
play

Operations describe the class behavior


and appear in the third compartment.

Software Design (UML)

SERG

Depicting Classes
When drawing a class, you neednt show attributes and operation
in every diagram.
Person

Person

name
: String
birthdate : Date
ssn
: Id

Person
name
address
birthdate

Person

Person
eat
play

Software Design (UML)

eat()
sleep()
work()
play()

SERG

Relationships
In UML, object interconnections (logical or physical), are
modeled as relationships.
There are three kinds of relationships in UML:
dependencies
generalizations
associations
aggregation
composition
Software Design (UML)

SERG

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.

CourseSchedule
Course
add(c : Course)
remove(c : Course)

Software Design (UML)

SERG

Generalization Relationships
Person

Student

A generalization connects a subclass


to its superclass. It denotes an
inheritance of attributes and behavior
from the superclass to the subclass and
indicates a specialization in the subclass
of the more general superclass.

Software Design (UML)

SERG

Association Relationships
If two classes in a model need to communicate with each other,
there must be link between them.
An association denotes that link.

Student

Instructor

Software Design (UML)

SERG

Association Relationships (Contd)


We can indicate the multiplicity of an association by adding
multiplicity adornments to the line denoting the association.
The example indicates that a Student has one or more
Instructors:
Student

1..*

Software Design (UML)

Instructor

SERG

Association Relationships (Contd)


The example indicates that every Instructor has one or more
Students:

Student

1..*

Software Design (UML)

Instructor

SERG

Association Relationships (Contd)


We can also indicate the behavior of an object in an association
(i.e., the role of an object) using rolenames.

Student

teaches
1..*

learns from
1..*

Software Design (UML)

Instructor

SERG

Association Relationships (Contd)


We can also name the association.

Student

membership
1..*

Software Design (UML)

1..*

Team

SERG

Association Relationships (Contd)


We can specify dual associations.

member of
Student

1..*
1

1..*
president of

Software Design (UML)

Team

1..*

SERG

Association Relationships (Contd)


We can model objects that contain other objects by way of
special associations called aggregations and compositions.
An aggregation specifies a whole-part relationship between an
aggregate (a whole) and a constituent part, where the part can
exist independently from the aggregate. Aggregations are
denoted by a hollow-diamond adornment on the association.
Engine
Car

Transmission

Software Design (UML)

SERG

Association Relationships (Contd)


A composition indicates a strong ownership and coincident
lifetime of parts by the whole (i.e., they live and die as a
whole). Compositions are denoted by a filled-diamond
adornment on the association.

Window

1 .. *

Software Design (UML)

Scrollbar
Titlebar
Menu

SERG

Association/Composition Example

Software Design (UML)

SERG

Example Class diagram

Software Design (UML)

SERG

Case Study 1
A laboratory has several chemists who work on one or more
projects. Chemists (empid, Name, Phone_no) also may use
certain kinds of equipments (Serial_no, cost) on each project
(projected, start_date). The organization wishes to record
assign-date i.e., the date when the given equipment item was
assigned to a particular Chemist working on a specific project,
as well as total number of hours the chemist has used the
equipment for the project. The chemist must be assigned to at
least one project and one equipment item. Draw the class
diagram.

SERG

Case Study 2
POST OFFICE Management System- This simple website
holds the account information of the users and their details. It
also provide the details of the branches and also the
employees. It also provides the various type of bonds present
and term period. Rules and regulations can be viewed by
anyone. The user can login to this website. This also depicts to
send a telegram via credit card. Draw class diagram.

SERG

You might also like