You are on page 1of 46

3. UML 2.

0: Objects and
Classes
Objectives
 Discuss concepts of objects, classes, and relationships
 Define inheritance, polymorphism, aggregation, and composition
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
What is an Object?
UML Object Syntax
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
UML Class Notation

Student
-studentName: String
-stdentNo: int
-major: String
-gpa: double
+getStudentName(int
stuNo)
UML Class
Visibility Defined
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
What is a Relationship?
What is an Association?
Multiplicity
Register >
Student Course
* 1..7
0..4

s>
e
a ch
Te
Teacher 1..*
Multiplicity exercise
Association Classes
employ >
Company Person Class Company{
Name: String * * empName: String String name;
Address: String SSN: Number
DOB: Date String address;
SSN: Number
Integer ssn;
Job Person[] persons;
Salary: double
}

J1: Job
Salary = 1000
m:Person
empName= Mohammad
just: Company SSN= 123456
DOB= 1/5
Name= JUST
Address= Irbid
SSN = 112 J2: Job
Salary = 500

yu: Company
Name= Yarmouk
Address= Irbid
a:Person
J3: Job empName= Ali
SSN = 1234 Salary = 900 SSN= 556666
DOB= 15/9
Association Class Syntax
What is a Link?
Links and Associations
Navigability
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
Generalization
Example: Class Generalization
Class Inheritance
Overriding
Abstract Operations & Classes
Polymorphism
Class Canvas{
Array[Square] squares
Array[Circle] circles
Array[Triangle] triangles
Array[pentagon] pentagons

For (s: squares)


s.draw()
Pentagon
Class Square{ Class Circle{
For (c: circles)
Origin Origin
c.draw()
W r
H }
For (t: triangles)
} t.draw()

Class Canvas{ For (p: pentagons)


Array[Shape] shapes p.draw()
For (S: shapes)
s.draw()
} }
What happens?
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
Aggregation and Composition
Aggregation semantics
Transitive and asymmetric
Composition semantics
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
Abstract/Interface Classes
Interfaces
Interfaces
Class Filter{
Class Sensor{ int filterValue1(double value){
Filter f1 = new Filter(); for()
…… s1;
int v = f1.filterValue1(15.2); s2;
}
} }
JUST Irbid <<interface>>
Ipayment{
Class Student{ + epay(double: val): Boolean
String stuname; }
String stuno;


Ipayment p = new ….; Efawatercom Amman

Boolean payFees(double amount){ Class EFawatercomPayment implements IPayment{


p. epay(500); @Override
} Boolean epay(double: val){
} return payFees (val);
}
VISA USA
void payFees (double val){
Class OnlinePayment{
s1;
void payAmt (double val){
s2;
s1;
….
s2;
}
….
}
}
}
Composite Structures - Interfaces
Outline
 Objects
 Classes
 Objects and Class Relationships
 Inheritance and Polymorphism
 Aggregation and Composition
 Interface Realization
 Domain Model
Domain Model
How to Create a Domain Model?
Exercise - ATM
1 1 0..*
Bank ATM

Card CardReader CashDispenser Kbd/display receiptPrinter


cardNumber : int
startDate: Date
Exp: date
Pin: int
0..*

1
1 Owns > 1..* Account
Customer
0..* Balance : double

SavingAccount CheckingAccount

You might also like