26
Jerry Gao Ph.D. 9/2001 The UML: Object-Oriented Modeling The Unified Modeling Language (UML) Instructor: Jerry Gao Ph.D. San Jose State University email: [email protected] URL: http://www.engr.sjsu.edu/gaojerry Sept., 2001

Jerry Gao Ph.D.9/2001 The UML: Object-Oriented Modeling The Unified Modeling Language (UML) Instructor: Jerry Gao Ph.D. San Jose State University email:

  • View
    222

  • Download
    3

Embed Size (px)

Citation preview

Jerry Gao Ph.D. 9/2001

The UML: Object-Oriented Modeling

The Unified Modeling Language (UML)

Instructor: Jerry Gao Ph.D.

San Jose State Universityemail: [email protected]

URL: http://www.engr.sjsu.edu/gaojerry

Sept., 2001

Jerry Gao Ph.D. 9/2001

Object-Oriented Modeling

The Unified Modeling Language (UML)

Object-Oriented Modeling:- Focus on classes, objects and their relationships in the system- Represent the system using class diagrams and object diagrams- Is an iterative process

The major elements of the object-oriented modeling:- classes, objects and their relationships.

Purpose of object-oriented modeling:- to describe the system in terms of classes and objects- to provide a complete object-oriented view of the system - to help the understanding of the system through object-oriented analysis and modeling

Jerry Gao Ph.D. 9/2001

A Class Diagram and An Object Diagram

The Unified Modeling Language (UML)

1..*

Author

Name:Stringage: integer

Computer

Name:Stringmemory: integer

Uses0..1Class diagram

Bob:Author

Name:”Bob J.”age: 32

Bob’s Job PCComputer

Name:”Dell 466”memory: 64

Object diagram

Jerry Gao Ph.D. 9/2001

Object-Oriented Modeling

The Unified Modeling Language (UML)

How to perform object-oriented modeling?

- Step #1: Identify classes and objects in the system.- Find classes in the system- Identify their names and attributes- Identify their operations or functions

- Step #2: Find the relationships between classes- Find association relationships between classes- Find aggregation relationships between classes- Find inheritance (generalization) relationship between classes- Define the roles and cardinality of each class in the relationships.

- Step #3: Generate object diagrams based class diagrams

Jerry Gao Ph.D. 9/2001

Finding Classes

The Unified Modeling Language (UML)

Finding classes by asking the following questions:

- Do we have information that should be stored or analyzed?If so, check information-oriented classes. such as input/output

- Do we have external systems? If so, check the interface classes.

- Do we use any components, libraries? If so, check component-orientedclasses and library-oriented classes.

- Do we have any customers or users? If so, check user-oriented classes.

- Do we handle any devices? If so, check hardware-oriented interface classes.

- Do we have any business structure or organization involved in the system? If so, find organization-oriented classes.

Jerry Gao Ph.D. 9/2001

Class Examples

The Unified Modeling Language (UML)

Student

Name:Stringage: integerSS#: StringGPA: float

ReadStudent();UpdateStudent();CreateStudent();PrintStudent();

Figure

Size: Sizeposition: PositionType: FigureType

draw();setFiguer();scaleFigure();returnPosition();

operations

attributes

Jerry Gao Ph.D. 9/2001

Association Relationship Between Classes

The Unified Modeling Language (UML)

Student ComputerOwns

Student ComputerOwns

1..* 0..*

Multiplicity:

default one-to-one0..1 zero-to-one0..* or * zero-to-many1..* one-to-many

Jerry Gao Ph.D. 9/2001

Roles in Association Relationship Between Classes

The Unified Modeling Language (UML)

Person

married to

wife

husband

A husband is married to a wife. Both husband and wife are people.If a person is not married, then he or she cannot play the role of husband or wife, which means the married to association is not applicable.

Car Persondrives* *

company car driver

role

A person plays the role of a driver, and a car plays the role of a company car the relationship.

Jerry Gao Ph.D. 9/2001

Aggregation Relationship Between Classes

The Unified Modeling Language (UML)

Navy WarshipContains

Team Personmembers

* *

** Normal Aggregation

Shared Aggregation

A team is composed of team members. One person could be a member of many teams.

Jerry Gao Ph.D. 9/2001

Aggregation Relationship Between Classes

The Unified Modeling Language (UML)

Composition Aggregation

window

listbox

text

button

menu

*

*

*

*

contains

Jerry Gao Ph.D. 9/2001

Generalization Relationship Between Classes

The Unified Modeling Language (UML)

Normal Generalization -> Inheritance

Part-timeStudent

Student

Full-timeStudent

Part-timeStudent

Student

Full-timeStudent

Jerry Gao Ph.D. 9/2001

A Class Diagram for Financial Trading

The Unified Modeling Language (UML)

Customer Portfolio Trader

Instrument

Bond Stock Stock Option

1 Owns 1..* 1..* Handles 1

0..*

0..*

Con

tain

sC

onta

ins

Jerry Gao Ph.D. 9/2001

Packages

The Unified Modeling Language (UML)

Subsystem B

Subsystem A

Subsystem E

Subsystem C

Subsystem D

dependency

Jerry Gao Ph.D. 9/2001

Packages

The Unified Modeling Language (UML)

Subsystem B

Subsystem A

Subsystem D

Subsystem C

Subsystem E

Jerry Gao Ph.D. 9/2001

The UML: Dynamic Modeling

The Unified Modeling Language (UML)

Instructor: Jerry Gao Ph.D.

San Jose State Universityemail: [email protected]

URL: http://www.engr.sjsu.edu/gaojerry

Sept., 2001

Jerry Gao Ph.D. 9/2001

Dynamic Modeling

The Unified Modeling Language (UML)

Dynamic Modeling:- Focus on dynamic behaviors in the system- Use state, sequence, collaboration, and activity diagramsto present the behaviors of the system- Demonstrate how the objects interact dynamically

The results of dynamic modeling:

- State diagrams: -> describing object states and their changes in terms of events.

- Sequence diagrams:-> describing how objects interact and communicate with each other.

- Collaboration diagrams:-> describing how objects collaborate together by interactions

- Activity diagrams: -> another shows the object interactions for functionality and actors.

Jerry Gao Ph.D. 9/2001

The Notation of State Diagram

The Unified Modeling Language (UML)

State 1 State 2Event

State

starting point

State

end point

State Name

State Vars

Activities

Jerry Gao Ph.D. 9/2001

A State Diagram for An Elevator

The Unified Modeling Language (UML)

On first floor

Movingup

MovingDown Idle

Moving tofirst floor

Go up(floor)

Active at floor

Go up(floor)

Arrive at floor

Go down(floor)

Arrive at first floor

Time out

Jerry Gao Ph.D. 9/2001

A State Diagram for An Elevator

The Unified Modeling Language (UML)

On first floor

Moving up

do/moving to floor

Moving down

do/moving to floor

Idletimer = 0

do/increase timer

Moving tofirst floor

Go up(floor)Active at floor

Go up(floor)

Arrive at floor

Go down(floor)

Arrive at first floor

[Timer = time out] Guard-condition

Dynamic Modeling

Instructor: Jerry Gao Ph.D.

San Jose State Universityemail: [email protected]

URL: http://www.engr.sjsu.edu/gaojerry

Sept., 2001

Topic: The Unified Modeling Language

Jerry Gao Ph.D. 9/2001

Sending Messages between State Diagrams

All Rights Reserved

Off On

On()

Off()

Play()Stop()

Off On/Stop

On()

Off()

Off()/Stop()

On/Play

Play()

Stop()

CD PlayerStop()Play()On() Off()

Remote control

Topic: The Unified Modeling Language

Jerry Gao Ph.D. 9/2001 All Rights Reserved

An And-Substates Example

Low Speed High Speed

Forward Backward

Running

concurrent substates

Sequence Diagram

Instructor: Jerry Gao Ph.D.

San Jose State Universityemail: [email protected]

URL: http://www.engr.sjsu.edu/gaojerry

Sept., 2001

Sequence Diagram

Sequence diagrams:- illustrate how objects interact with each other.- focus on interacting message sequences between objects

:ObjectNameSimple message

Synchronous message

[Guard-condition]

Return

Activation

lifeline

Sequence Diagram Example

:Computer

Print(ps-file)

Activation

lifeline

:PrinterServer :Printer

Print(ps-file)

Object[no queue]Print(ps-file)

Guard-condition

Synchronousmessage

Return

simplemessage

Sequence Diagram Example

:Computer

Print(file)

:PrinterServer :Printer

Print(file)

[printer free]Print(file)

:Queue

[printer busy]Store(file)