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

UML

Class & Object Diagram


I

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 1
Object-oriented modelling
involves classes which function as
types that describes their
instances which are called
objects.

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 2
Object-oriented modelling
includes description of:
- object properties
- links between objects
- object behaviour

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 3
Objects
Icons representing
“real world objects”
of different types.

myChair: :Bus :Plane


Represented in the Object name and no type Object name (id) and type
UML notation.
:Truck :Ship PN62001:Car
Anonymous object, only type is given

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 4
Classify Objects
Some objects share the same type of qualities so we
may formulate a general concept = define a class.

This is a form of abstraction - some of the differences between


the objects are “abstracted away” (ignored).
Furniture

myChair: yourChair: theBrownSofa:

A class describes a set of objects that have the same


type of attributes, behaviour and relationships.
relationships

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 5
Class and Objects
UML Notation
class
objects
Person class name
SSN
person1:Person person2:Person
name attributes
address (fields)
SSN = 123... SSN = 122...
drive() operations name= Jane name = James
Run() address=Norway address = USA
(methods)
...

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 6
Making a Model
• You are to solves some problem in a domain.

• Simplify and find what is essential for your problem.

• OO modelling: ”Objects from reality” are mapped


”directly” onto objects in your model.

chair: Seated in

Tom:
car: owner

reality mapping model

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 7
Subclass and Superclass
The class of human beings

The subclass of ”female objects” Person


People is superclass of Female
Female Male
Jane: James:

Person
The classes represented in
the UML notation.
Female Male

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 8
Class Hierarchy ~
Reuse by Inheritance
An employee is a special type of person, so if you already have a
Person class and needs an Employee class, then inheritance allows
you to reuse class Person.

superclass Person
Jane:Employee
SSN
name SSN = 123...
address name = Jane
inheritance Employee is a
address = Norway
or specialization specialisation
title = accountant
of Person
department = accounting
subclass Employee
An object of type Employee
title
department
UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 9
Multiple Person
name

Inheritance Employee
title
Owner

• UML and OWL supports


multiple inheritance. WorkingOwner

• Some object-oriented Cassette Book

theoreticians claim that volume : Integer volume : Integer

multiple inheritance should


not be used! (e.g., Java). CassetteBook

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 10
One Common
Ancestor for All
Classes
Object

hashCode

In Java all classes have a common ancestor called Object.


In OWL it is called Thing.
In C++ UML this is not the case. Person Car

Employee

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 11
Linking Objects
Objects are typically connected in some way or another. For
example: Jane is married to James, Jane owns a car.

ownership
Person Car

married association Class Model

Jane:Person
:ownership
someWreck:Car
Object Model
(model instance of the
class model)
:married
links
James:Person

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 12
Part-of Relation
Some objects can be seen as compost of other objects.

Head
1

1
2 1
Arm Person
1

Leg

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 13
There Are Typically Many
Ways to Classify Objects
Jim may be classified as a person, a male person, an
employee, a student and so on - the context decides.

xxx:
xxx:
xxx:
xxx:
xxx:
xxx: xxx:

xxx: xxx:

xxx: xxx: xxx:

xxx:
xxx: xxx:

xxx: xxx:
xxx:
xxx:

the classes may overlap


(or they may be disjoint)

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 14
How to model
gender?

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 15
Different Models May be
Possible!
Person Gender Person
gender : String Gender Person

Female Male
Female Male

Gender Person

Androgyni

Female Male Undecided


?
Gender Person

Female Male Androgyni

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 16
Object Behaviour
CoffeeMachine
Person
pourCoffe()
operations ~ behaviour
addMilk()
addOneLumpOfSugger()

Jane : Person office : CoffeeMachine

pourCoffe( ) sending a message


addOneLumpOfSugger( )

addOneLumpOfSugger( )
time
addMilk( )

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 17
An Object-Oriented Program
------

Objects Work Together and Solve Problems

• Objects have identity.


identity
• Objects have state,
state the values of the attributes defines
the state. The state change when the values of the
attributes change.
• Some objects are linked together.
together
• The objects communicate by sending messages to each
other (messages follows the links).
Sending a message is the same as asking an object to
perform one of its operations (methods).
UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 18
Descriptive Models
Model
describedBy

given
System

E.g. physics :
- the system under study is nature (which is given)
- the mission is to come up with a description (model) that
is so good that it can be used to predict and explain
natural phenomenon.

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 19
Specification (Prescriptive)
& Descriptive Model
Model The “specifiedBy role” is a Model
describedBy specialization of the specifiedBy
“describedBy role.”
given describedBy specifiedBy specifies
System System

In physics the system under study is nature (which The specification of a software system;
is given); the mission is to come up with a description the implementation (system) must conform
(model) that is so good that it can be used to predict to the model.
and explain natural phenomenon.

A system is a group of interacting, interrelated, or


interdependent elements that form a complex whole.

Person Car :Person :Car


1 *
name name=“Bob”
:Car

Model A Model Instance snapshot

UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 20

You might also like