Vous êtes sur la page 1sur 52

DefiningDomainModels

UsingClassDiagrams
Dumitru Radoiu
DumitruRadoiu
Spring2009
PETRU MAIOR UNIVERSITY

Object-Oriented World

time

OO Analysis

Create the
vocabulary

Requirements

OO Design

Give
vocabulary
ocabu a y
behavior
(model the
system)

OO Programming

Program the
model
ode

Deliverables

Activity

UMLDiagram

Understand SystemUsage

UseCaseDiagram

Identify Classes
IdentifyClasses

High Level Class Diagram 9


HighLevelClassDiagram

DefineWorkflows

ActivityDiagram

Object-Oriented World

time

OO Design

OO Analysis

Create the
vocabulary

Requirements

Give
vocabulary
ocabu a y
behavior
(model the
system)

OO Programming

Program the
model
ode

A ti it
Activity

UML Di
UMLDiagram

Identifyinteractions
amongobjects

9
Sequenceand
CollaborationDiagrams

Analyzestatechanges
l
h

SateDiagrams

Refineclassdiagrams

ClassDiagrams

Deliverables

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

Why We Model Class Diagrams


REAL WORLD

Real world items

Mapping
Mapping

OO Design

OO Analysis

OO WORLD

Equivalent abstract entities


Data
Functionality

Needs

Requirements

Data
Functionality

OO Programming

Why We Model Class Diagrams


Real world business items

Mapping

OO Analysis

OO Design

OO Programming

Equivalent business entities

Needs

Requirements

Technical entities

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

Notation
Name of the class

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Attributes ((data))

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Operations (behavior)

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Association

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

1 2
1..2

Guards>
-Child
Lion

LittleBoy
1..*

Notation
Association name

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

1 2
1..2

Guards>
-Child
Lion

LittleBoy
1..*

Notation
Multiplicity

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Rolename

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
IInvisible
i ibl ffor access
for system classes
(private)

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Visible for access
for system classes
(public)

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

+ Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation
Invisible for access
for classes outside
the system
(protected)

Animal
-Nr.OfEyes
y
- Nr.OfLegs

Parent
-Children

# Eat()
+Sleep()
Sleep()

-Guardian

-Child
Lion

LittleBoy
1..*

1 2
1..2

Notation

Public Interface

Cl
ClassName
N
- Attribute1
+ Attribute2
- operation1()
+ operation2()
- operation3()

By default invisible

By default visible

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

What makes a Class

Cl
ClassName
N
-Attribute1
- Attribute2
+ operation1()
+ operation2()

What makes a Class

Animal
Lion
Attributes and operations are hidden

Animal
+ Eat()
+Sleep()

No attributes and operations in the class

Animal

+ Eat()
+Sleep()

C
Cannot
t ttellll if th
there are attributes
tt ib t iin th
the class
l
No attributes in the class

What makes a Class

Animal
Animal
-Attribute1
- Attribute2

-Attribute1
- Attribute2

Cannot tell if there are operations in the class


No operations in the class

Objects: Instances of Classes

MathTeacher : Teacher

MathTeacher : Teacher
+TeacherName = George
- Password = georgepass

MathTeacher : Teacher
TeacherName
Password

MathTeacher : Teacher
+ ChangePassword()
+ RecordGrades()

+ ChangePassword()
+ RecordGrades()
+TeachClasses()

Packages

MathTeacher : Grading :: Teacher

Grading :: Teacher

Package name

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

How to Give Attributes Detail

Student
+ Name : String
- Password : String
+ GradeLevel : Integer

Visual Basic Data Types

Boolean

Double

Single

Byte

Integer

String

Currency

Long

Variant

How to Give Attributes Detail: Multiplicity

Student
+ Name [1] : String = NewStudent
- Password [1] : String
+ GradeLevel [1] : Integer = 1
+ Grades [0..*] : Integer = {4,7,9,8}

How to Give Attributes Detail: Derived Attributes

Student
+ Name [1] : String = NewStudent
- Password [1] : String
+ GradeLevel [1] : Integer = 1
+ Grades [0..*] : Integer = {4,7,9,8}
+ / GPA [1] : Double = Null

Business logic is
included in a note

{if (NumberOfGrades = 0) then


GPA = Null
else
GPA = Sum(Grades)/(NumberOfGrades)}

How to Give Attributes Detail: Derived Attributes

Student
+ Name [1] : String = NewStudent
- Password [1] : String
+ GradeLevel [1] : Integer = 1
+ Grades [0..*] : Integer
+ / GPA [1] : Double = Null

CurrentStudent : Student
+ Name [1] : String = NewStudent
- Password [1] : String
+ GradeLevel [1] : Integer = 1
+ Grades [0..*] : Integer = {4,7,9,8}
+ / GPA [1] : Double = 7.00

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

How to Give Attributes Detail

Student
+ Name [1] : String = NewStudent
- Password [1] : String
+ GradeLevel [1] : Integer = 1
+ Grades [0..*] : Integer
+ / GPA [1] : Double = Null
+ AddGrade(in Grade : Integer = 10)
+ ClearGrades()
+ ChangePassword(in OldPassowrd : String, in NewPassowrd : String) : Boolean

Operation

Parameter
name

Data type

Return value

Agenda

WhyWeModelClassDiagrams
Why
We Model Class Diagrams
Notation
WhatMakesaClass
HowtoGiveAtributesDetail
HowtoGiveOperationsDetail
ModelaClassDiagram:CaseStudy
g
y

Model a Class Diagram: Case Study


distribute
electronically
record g
grades

<<include>>
save grades

Teacher

upgrade
pg
g
grades

<<include>>

<<include>>

load grades

logon
<<include>>
view
i
grades
d

Administrator

generate report
cards

Student

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyallnounsandmakethemclasses

Model a Class Diagram: Case Study


distribute
electronically
record g
grades

<<include>>
save grades

Teacher

upgrade
pg
g
grades

<<include>>

<<include>>

load grades

logon
<<include>>
view
i
grades
d

Administrator

generate
report cards

Student

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)

Model a Class Diagram: Case Study


distribute
electronically
record g
grades

<<include>>
save grades

Teacher

upgrade
pg
g
grades

<<include>>

<<include>>

load grades

logon
<<include>>
view
i
grades
d

Administrator

generate
report cards

Student

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)
o Reviewusecasesandmakesuretheyallhaveahome(class)

Model a Class Diagram: Case Study


distribute
electronically
record g
grades

<<include>>
save grades

Teacher

upgrade
pg
g
grades

<<include>>

<<include>>

load grades

logon
? New class!!!

<<include>>
view
i
grades
d

Administrator

generate
report cards

Student

Model a Class Diagram: Case Study

Teacher

Grades

ReportCard

WebSite
Dont forget the GUI
to transfer Actors
actions

Administrator
Student

Logon
g

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)
o Reviewusecasesandmakesuretheyallhaveahome(class)
2. Begincreatingassociations

Model a Class Diagram: Case Study

Teacher

Grades

ReportCard
p

WebSite

Administrator
Student

Logon
g

Model a Class Diagram: Case Study

maintains >

< contains
ReportCard
p

Grades

Teacher

^ displays
^ generates
WebSite
uses >
^ grants access to
Administrator
Logon
g

Student
uses >

< uses

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)
o Reviewusecasesandmakesuretheyallhaveahome(class)
2. Begincreatingassociations
3. Identifymultiplicity

Model a Class Diagram: Case Study

maintains >

< contains
ReportCard
p

Grades

Teacher

^ displays
^ generates
WebSite
Change name to
OnlineUser uses >

^ grants access to
Administrator
Logon
g

Student
uses >
Little functionality;
y;
move it to WebSite

< uses

Model a Class Diagram: Case Study

maintains >

< contains
Grades

Teacher

ReportCard
p

^ generates
^ displays

Administrator

uses >
Student

WebSite

Model a Class Diagram: Case Study

maintains >

< contains
ReportCard
p

Grades

Teacher
1

1..*

1..*

1..*
^ generates

^ displays
1
Administrator

uses >
Student

WebSite

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)
o Reviewusecasesandmakesuretheyallhaveahome(class)
2. Begincreatingassociations
3. Identifymultiplicity
4. FindAttributesandOperations

Model a Class Diagram: Case Study

maintains >

< contains
ReportCard
p

Grades

Teacher
1

1..*

1..*

1..*
^ generates

^ displays
1
Administrator

uses >
Student

WebSite
+ Logon()
+ View()

Model a Class Diagram: Case Study

maintains >

Grades

< contains
ReportCard
p

Teacher
1

1..*

1..*
+RecordGrades()
+UpgradeGrades()
+Distribute()
Di t ib t ()
-Save()
-Load()

1..*
^ generates
1

^ displays
Administrator

uses >
Student

WebSite
+ Logon()
+ View()

Model a Class Diagram: Case Study


1. Identifyclassesandassociationsfromusecases
o Identifyall nouns andassociatethemclasses
o Associateclassestoactors(ifyouplantoidentifyapieceof
information about THAT actor or provide functionality for THAT
informationaboutTHATactororprovidefunctionalityforTHAT
actor)
o Reviewusecasesandmakesuretheyallhaveahome(class)
2. Begincreatingassociations
3. Identifymultiplicity
4. FindAttributesandOperations
5. Detailattributesandoperationsandgivethemparameters,datatypes
and initial values
andinitialvalues