34
OOAD 1 Chapter 1 Introduction to Modeling Java and UML 鄧鄧鄧 [email protected] http://w3.im.knu.edu.tw/~ joseph

Introduction to Modeling Java and UML

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Introduction to Modeling Java and UML

OOAD 1

Chapter 1 Introduction to Modeling Java and UML

鄧姚文[email protected]

http://w3.im.knu.edu.tw/~joseph

Page 2: Introduction to Modeling Java and UML

OOAD 2

Agenda What is modeling? UML Modeling software systems with

UML Modeling process

Page 3: Introduction to Modeling Java and UML

OOAD 3

Introduction Why Java?

A good object-oriented programming language

Web-enabled enterprise computing (J2EE)

Excellent support for exception handling and concurrency

Other OO languages Small Talk, C++, Object Pascal, C#,

Python

Page 4: Introduction to Modeling Java and UML

OOAD 4

Goal of This Book Be able to

Communicate an understanding of OO modeling theory and practice to others

Communicate an understanding of UML notation to others

Critically review a wide variety of UML software models Use UML to create a detailed understanding of the

problem from the user’s perspective Use UML to visualize and document a balanced solution

using the full suite of Java technologies Use UML to describe other technologies and class

libraries

Page 5: Introduction to Modeling Java and UML

OOAD 5

What Is Modeling? A model is a simplification with a

purpose Use precisely defined notation to

describe and simplify a complex and interesting structure, phenomenon, or relationship

Real-world examples The solar system model Mathematical models

Page 6: Introduction to Modeling Java and UML

地軸傾斜

北極冬天沒陽光

南極夏天沒黑夜

以太陽系模型說明極地永晝與永夜以太陽系模型說明極地永晝與永夜

Page 7: Introduction to Modeling Java and UML

OOAD 7

What Is Modeling? (cont’d) Simplification

Less complex, more accessible Varying perspectives

Describe the system from different perspectives

Help developers manage complexity Common notation

To facilitate communication Allows developers to combine their efforts and

to work in parallel

Page 8: Introduction to Modeling Java and UML

OOAD 8

UML Unified Modeling Language A language for specifying,

visualizing, constructing, and documenting the artifacts of software systems

A set of precise notations Helps developers create ideas and

communicate them An open standard controlled by OMG

Page 9: Introduction to Modeling Java and UML

OOAD 9

UMLThe Basics Abstraction 抽象化,摘要

只要抓住重點,不必每樣細節都考究 A simplification or model of a complex concept,

process, or real-world object Help people understand something at an appro

priate level Different people would build different abstracti

ons for the same concept Highlight the characteristics and behavior of so

mething that is too complex to understand in its entirety

Page 10: Introduction to Modeling Java and UML

OOAD 10

UMLThe Basics Encapsulation 封裝

凸顯重要特質隱藏內部細節 Highlight the important aspects of an obj

ect Hide the cumbersome internal details of

the object Make the system easier to understand an

d to reuse Make a system more extendible

Page 11: Introduction to Modeling Java and UML

OOAD 11

UMLThe Basics

Object A particular and finite element in a large model

Visible or invisible Persistent or transient

State: describes characteristics and current condition

Behavior: defines the actions that other objects may perform on the object

Method: a service or responsibility that an object exposes to other objects

Each has a unique identifier Limited responsibility and cooperation

myCar : ToyotaTercel

Page 12: Introduction to Modeling Java and UML

OOAD 12

UMLThe Basics Class

A group of objects that have something in common

Captures a particular abstraction Provides a template for object creation Each objects created from a class is

identical in The type of data they can hold The type and number of objects they know about The logic for any behavior they provide

+attackKenDoll()

-name : String-rank : String#carryingRifle : Boolean

ToySoldier

Page 13: Introduction to Modeling Java and UML

OOAD 13

UMLThe Basics Relationships between objects

Dependency Association Aggregation Composition

Page 14: Introduction to Modeling Java and UML

OOAD 14

Dependency Short-term dependency An object may create another object as

part of a method, ask it to perform some function, and then forget about it

Customer

+ringUpFood()+processPayment()

Cashier

Page 15: Introduction to Modeling Java and UML

OOAD 15

Association An object keeps a reference to another

object and can call the object’s, methods as it needs them

An object may receive an object as a parameter to a configuration method and keep a reference to the object

CarPerson

Page 16: Introduction to Modeling Java and UML

OOAD 16

Aggregation An object is part of a greater whole The contained object may participate

in more than one aggregation relationship, and exists independently of the whole

ProjectTeam SoftwareDeveloper

* *

Page 17: Introduction to Modeling Java and UML

OOAD 17

Composition An object is owned by a greater whole The contained object may not participate in

more than one composition relationship and cannot exist independently of the whole

Engine SmallGear

1 *

Page 18: Introduction to Modeling Java and UML

OOAD 18

UMLThe Basics Navigability

The control relationship The arrow indicates direction of control

+startEngine()

Car

+getSpinSpeed()

Wheel

1 *

Page 19: Introduction to Modeling Java and UML

OOAD 19

UMLThe Basics Multiplicity

The number of relationships No default multiplicity

+go()+displayStatus()

CarPerson

1..* * +turnOn()

Engine

1 1 +spin()

SmallGear

1 *

Page 20: Introduction to Modeling Java and UML

OOAD 20

UMLThe Basics Interface

Defines a set of related behavior Does not specify the actual implementation

for the behavior Specify the signature of one or more methods

A class realizes an interface by implementing each method in the interface

SoundSimulator

+makeNoise()

<<interface>>INoiseMaker

1 *

Page 21: Introduction to Modeling Java and UML

OOAD 21

UMLThe Basics Polymorphism

Multiple implementation of a single abstraction

Abstraction are captured in classes and in interfaces

Page 22: Introduction to Modeling Java and UML

OOAD 22

Polymorphism Through Realization

SoundSimulator

+makeNoise()

<<interface>>INoiseMaker

1 *

+makeNoise()

Trumpet

+makeNoise()

Tiger

Page 23: Introduction to Modeling Java and UML

OOAD 23

Polymorphism Through Inheritance

SoundSimulator

1 *

+makeNoise()

Trumpet

+makeNoise()

Tiger

+makeNoise()

SimulationElement

Page 24: Introduction to Modeling Java and UML

OOAD 24

Modeling Software Systems with the UML UML enables building a single

coherent model that describes a software system from several perspectives Internal consistency Distinct views

Participants can use the same model and speak the same language throughout the development process

Page 25: Introduction to Modeling Java and UML

OOAD 25

The Customer’s Perspective Use case

Defines and describes a discrete way in which users get value from the system

Text description of each use case Including the details of the interactions

between the user and the system Activity diagram

Visual description of the interaction between the system and the user for a use case

Page 26: Introduction to Modeling Java and UML

OOAD 26

The Developer’s Perspective Class diagram

Defines and constrains a group of objects in detail Shows the state, behavior, and relationships

State chart Describe the state-dependent behavior for a class How an object responses to requests depending

on its internal configuration Package diagram

How different parts of a system depend on one another

Page 27: Introduction to Modeling Java and UML

OOAD 27

The Developer’s Perspective (cont’d) Sequence diagram

How objects interact with one another to provide the functionality

Indicates the order of the interaction Collaboration diagram

Revealing the relationship between objects

Page 28: Introduction to Modeling Java and UML

OOAD 28

Modeling Process1. The developers and customers use

the UML to understand the problem from the customer’s point of view

2. The developers use UML to understand the problem from their own point of view

3. The UML model is used as a resource by the implementers of the system

Page 29: Introduction to Modeling Java and UML

OOAD 29

Modeling Process (cont’d) Requirements gathering Analysis Technology selection Architecture Design and implementation

Page 30: Introduction to Modeling Java and UML

OOAD 30

Requirements Gathering Understand the problem from the

customer’s point of view Do NOT concern for technology or

system design In this process, developers create

Use case diagrams Text use case descriptions Activity diagrams

Page 31: Introduction to Modeling Java and UML

OOAD 31

Analysis Understand the problem from the

developer’s point of view Still do NOT concern for technology Discover the roles and responsibilities

that must be filled in the system In this process, developers create

Class diagrams Sequence diagrams Collaboration diagrams

Page 32: Introduction to Modeling Java and UML

OOAD 32

Technology Selection Categorize the system in terms of its

technological requirements Select the most appropriate technologies

to fulfill these well-defined needs Produce a high-level summary of the

technological requirements and a list of appropriate technologies for the system

No additional UML diagrams are produced

Page 33: Introduction to Modeling Java and UML

OOAD 33

Architecture Describe the system at high level Decompose the system into smaller

parts (subsystems) Highlight relationships between parts Hide details of each part In this process, developers create

Primary class diagrams Package diagrams

Page 34: Introduction to Modeling Java and UML

OOAD 34

Design and Implementation Design

Use all the results from the previous steps Create a model of objects that interact to

provide the system’s functionality The last chance to validate the solution

Implementation Write the code according to the design