Vous êtes sur la page 1sur 20

Introduction to

Object-Oriented Design
and the UML
Object-Oriented Modeling

 UML: Unified Modeling Language


Emerging OO Modeling Standard
 What is depicted?
System functionality
Class details and static relationships
Object interaction
State transition within an object
Modeling Techniques

 Use Cases/Use Case Diagrams


 Class Diagrams
 CRC Cards
 Interaction Diagrams
 State Diagrams
Example:
Use Case Diagram
LIBRARY SYSTEM

Facilitate Borrow

Librarian Borrower
Search for Book

Facilitate Return
Class Diagrams
and CRC Cards

 Class Diagrams: similar to ER Diagrams


but in addition, it incorporates
methods, not just attributes for each entity
inheritance
 Class-Responsibility-Collaboration Cards
technique that depicts responsibilities of
classes with respect to other classes (hints on
both data and behavior details)
Example:
Interaction Diagram
2: checkIfAvailable()
Borrow
:Book
Screen

1: checkIfDelinquent()
3: borrowBook()

4: setBorrower()

:Borrower
Example:
State Diagram (Book)

start
Reserved

New Borrowed

Librarian activates Borrower returns book


book as available Available
Object-Oriented Design
Models

 Static Model
Class Diagrams
 Dynamic Model
Use Cases, Interaction Diagrams, State
Diagrams, others
OO Static Model

 Class Diagrams
 Relationships
Association
Aggregation/Composition
Inheritance
 Attribute and Method names
Classes in a Class Diagram

 Class name only Example


Bank
Class Name Account

 With Details Example


Bank Acct
Class Name
double balance
attributes
deposit()
methods
withdraw()
Relationships

 Inheritance (arrow)
example: between Secretary and Employee
 Composition/Aggregation (diamond)
example: between Car and Wheel
 Association (line)
example: between Borrower and Book
Inheritance

Employee

public class Secretary extends Employee {



}

Secretary
Composition

4
Car Wheel
w[]

public class Car {


Wheel w[];
...
public Car() {
w = new Wheel[4];

}
...
}
Association

0..1 0..3
Borrower Book
currBorr bk[]

public class Borrower { public class Book {


Book bk[]; Borrower currBorr;
… …
public Borrower() { }
bk = new Book[3];
}
}
OO Dynamic Model

 Goal: Represent
Object behavior
Object interaction
 Traditional (relational) Dynamic Modeling
Data Flow Diagrams (DFDs)
Problem: Processes separate from data
Need modeling notation that highlight tight
relationship between data & processes
DFD Example
(Inventory Management)

Delivery info
Accept and Post
Delivery
Transaction

Item Master
OO Counterpart:
Object Interaction
new (delivery info)
Encoder :Transaction

post (item count)

:Item Master
Interaction Diagrams

 Rectangles: Classes/Objects
 Arrows: Messages/Method Calls
 Labels on Arrows
sequence number
method name
more details, when necessary (conditions,
parameters, types, return types)
Interaction Diagram:
Borrow-Book Example

2: avail = checkIfAvailable():boolean
Borrow
Screen
b:Book
1: delinq = checkIfDelinquent():boolean
3:[!delinq & avail] borrowBook(Book b)

4: setBorrower(r)
r:Borrower
Methods

 Interaction Diagrams suggest methods for


classes
consequence on detailed class diagram
 The label(s) of an arrow should be a
method of the class the arrow points to
 Library System
Borrower class should have at least two
methods (checkIfDelinquent and borrowBook)

Vous aimerez peut-être aussi