uml class & object diagram€¦ · object-oriented modelling involves classes which function as...

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

Upload: others

Post on 27-Jun-2020

30 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

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

UML

Class & Object Diagram

I

Page 2: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

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

Page 3: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

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

Page 4: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Objects

myChair: :Bus :Plane

:Truck :Ship PN62001:Car

Anonymous object, only type is given

Object name and no type Object name (id) and typeRepresented in the

UML notation.

Icons representing

“real world objects”

of different types.

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

Page 5: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Classify Objects

myChair: yourChair: theBrownSofa:

Furniture

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).

A class describes a set of objects that have the same type of attributes, behaviour and relationships.

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

Page 6: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Class and Objects

UML Notation

person1:Person

SSN = 123...

name= Jane

address=Norway

person2:Person

SSN = 122...

name = James

address = USA

objects

Person

SSN

name

address

drive()

Run()

...

class

attributes

(fields)

operations

(methods)

class name

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

Page 7: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Introduction to Object-oriented Software Development, Jan.Pettersen Nytun page no. 7

How does one

show

Classes and Objects

in a

Java Program?

Page 8: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

public class Patient extends Person {

private Journal patientsJournal;

public Patient(String name, Doctor createdBy) {

super(name);

patientsJournal = new Journal();

patientsJournal.setCreatedBy(createdBy);

patientsJournal.setConcerns(this);

}

public Journal getPatientsJournal(){ return patientsJournal; }

public void setPatientsJournal(Journal patientsJournal) {

this. patientsJournal = patientsJournal;

}

} Introduction to Object-oriented Software Development, Jan Pettersen Nytun page no. 8

Page 9: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

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.

reality

chair:

car:

Tom:

Seated in

owner

modelmapping

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

Page 10: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Subclass and Superclass

The class of human beings

The subclass of ”female objects”

People is superclass of Female

Jane: James:

Person

Female Male

The classes represented in

the UML notation.

Person

Female Male

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

Page 11: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Class Hierarchy ~

Reuse by InheritanceAn 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.

Person

SSN

name

address

Employee

title

department

An object of type Employee

Jane:Employee

SSN = 123...

name = Jane

address = Norway

title = accountant

department = accounting

inheritance

or specialization

Employee is a

specialisation

of Person

superclass

subclass

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

Page 12: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Multiple

Inheritance

Person

name

Employee

titleOwner

WorkingOwner

• UML and OWL supports multiple inheritance.

• Some object-oriented theoreticians claim that multiple inheritance should not be used! (e.g., Java).

Cassette

volume : Integer

Book

volume : Integer

CassetteBook

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

Page 13: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

One Common

Ancestor for All

Classes

In Java all classes have a common ancestor called Object.

In OWL it is called Thing.

In C++ UML this is not the case.

Object

Person Car

Employee

hashCode

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

Page 14: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Linking ObjectsObjects are typically connected in some way or another. For example: Jane is married to James, Jane owns a car.

Jane:Person someWreck:Car

James:Person

:married

:ownership

links

Person Carownership

married associationClass Model

Object Model(model instance of the

class model)

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

Page 15: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Part-of Relation

Some objects can be seen as compost of other objects.

Person

Leg

Head

Arm 2

1

2

1

1

1

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

Page 16: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

There Are Typically Many

Ways to Classify Objects

the classes may overlap

(or they may be disjoint)

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

Jim may be classified as a person, a male person, an

employee, a student and so on - the context decides.

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

Page 17: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

How to model

gender?

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

Page 18: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Different Models May be

Possible!Gender

Female Male

PersonPerson

gender : String

Gender

Female Male

Person

Undecided

Gender

Female Male

Person

Androgyni

Gender

Female Male

Person

Androgyni

?

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

Page 19: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

8/17/2016Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 19,

“Not all people feel at home in the categories male or female.

Professor of sexology Esben Esther Pirelli Benestad believes there

are seven different genders.”

[https://www.nrk.no/norge/visste-du-at-det-finnes-sju-kjonn_-1.13057760]

Page 20: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

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

Object Behaviour

Jane : Person office : CoffeeMachine

pourCoffe( )

addOneLumpOfSugger( )

addOneLumpOfSugger( )

addMilk( )time

sending a message

lifeline for object

office:CoffeeMachine

canUse

operations / behaviour canBeUseBy *

*

Page 21: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

An Object-Oriented Program------

Objects Work Together and Solve Problems

• Objects have identity.

• Objects have state, the values of the attributes defines the state. The state change when the values of the attributes change.

• Some objects are linked 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. 21

Page 22: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Descriptive Models

System

Model

given

describedBy

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. 22

Page 23: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

Specification (Prescriptive)

& Descriptive Model

System

Model

given

describedBy

System

Model

specifies

specifiedBy

Person

name

Car1 *

:Person

name=“Bob”

:Car

:Car

In physics the system under study is nature (whichis given); the mission is to come up with a description(model) that is so good that it can be used to predictand explain natural phenomenon.

The specification of a software system;the implementation (system) must conformto the model.

Model A Model Instance snapshot

The “specifiedBy role” is aspecialization of the“describedBy role.”

A system is a group of interacting, interrelated, or interdependent elements that form a complex whole.

specifiedBydescribedBy

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

Page 24: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

What is a Domain Model

“A domain model is a model of the domain

within which an Enterprise conducts its

business. The Domain Model for one

Enterprise should be the same as that for any

other Enterprise conducting business in the

same do main. When we get down to more

detailed levels, different people have different

ideas about what constitutes a Domain Model.”

[http://www.aptprocess.com/whitepapers/DomainModelling.pdf]

8/17/2016Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 24,

Domain

Domain Model

given

describedBy

Page 25: UML Class & Object Diagram€¦ · Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram &

• A UML class diagram can be used to describe a

domain model.

• Some would say that a domain model is an

ontology.

• The model is a model of software which is the

main purpose of UML.

8/17/2016Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 25,

Domain

Domain Model

given

describedBy

System

Model

specifies

specifiedBy