39
Shanghai Jiao Tong University 上上上上上上上上上上上上 Object Oriented Analysis and Design Introduction to Object Technology

Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Embed Size (px)

Citation preview

Page 1: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Shanghai Jiao Tong University

上海交通大学软件工程中心

Object Oriented Analysis and Design

Introduction to Object Technology

Page 2: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 2

Outline

Introduction to object technology Concepts of Object Orientation

Page 3: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 3

What Is Object Technology?

A set of principles (abstraction, encapsulation, polymorphism) guiding software construction, together with languages, databases, and other tools that support those principles. (Object Technology - A Manager’s Guide, Taylor, 1997.)

Page 4: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 4

The Strengths of Object Technology

Reflects a single paradigm Facilitates architectural and code reuse Reflects real world models more closely Encourages stability Is adaptive to change

Page 5: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 5

Major object technology milestones

Simula

1967

C ++

Late 1980s

Smalltalk

1972

Java

1991

UML

1996

MDA

2003

The History of Object Technology

???

Future

Page 6: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 6

Where Is Object Technology Used?

Client/Server Systems and Web Development Object technology

allows companies to encapsulate business information in objects and helps to distribute processing across the Internet or a network.

Page 7: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 7

Where Is Object Technology Used? (cont.)

Real-time systems Object technology

enables real-time systems to be developed with higher quality and flexibility.

4

Page 8: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 8

Differences Between OO and Structured Design

Object-orientation (OO) Melds the data and data flow process together

early in the lifecycle Has a high level of encapsulation Promotes reuse of code differently Permits more software extensibility

Page 9: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 9

Outline

Introduction to object technology Concepts of Object Orientation

What is an object? Four principles of OO What is a class? Polymorphism and generalization Organizing model elements

Page 10: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 10

Truck

Chemical Process

Linked List

What Is an Object?

Informally, an object represents an entity, either physical, conceptual, or software.

Physical entity

Conceptual entity

Software entity

Page 11: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 11

A More Formal Definition An object is an entity

with a well-defined boundary and identity that encapsulates state and behavior. State is represented by

attributes and relationships.

Behavior is represented by operations, methods, and state machines. Object

Operations

Attributes

Page 12: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 12

An Object Has State State is a condition or situation during the life of

an object, which satisfies some condition, performs some activity, or waits for some event.

The state of an object normally changes over time.

Name: J ClarkEmployee ID: 567138Date Hired: July 25, 1991Status: TenuredDiscipline: FinanceMaximum Course Load: 3 classes

Name: J ClarkEmployee ID: 567138HireDate: 07/25/1991Status: TenuredDiscipline: FinanceMaxLoad: 3

Professor Clark

Page 13: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 13

An Object Has Behavior

Behavior determines how an object acts and reacts.

The visible behavior of an object is modeled by a set of messages it can respond to (operations that the object can perform).

Professor Clark’s behaviorSubmit Final GradesAccept Course OfferingTake Sabbatical

Maximum Course Load: 3 classesSub

mitF

inal

Gra

des(

)

AcceptCourseOffering()

TakeSabbatical()

Professor Clark

SetMaxLoad()

Page 14: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 14

An Object Has Identity

Each object has a unique identity, even if the state is identical to that of another object.

Professor “J Clark” teaches Biology

Professor “J Clark” teaches Biology

Page 15: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 15

Basic Principles of Object Orientation

Abs

trac

tion

Hie

rarc

hy

Object Orientation

Enca

psul

atio

n

Mod

ular

ity

Page 16: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 16

What Is Abstraction?

The essential characteristics of an entity that distinguishes it from all other kinds of entities.

Defines a boundary relative to the perspective of the viewer.

Is not a concrete manifestation, denotes the ideal essence of something.

Page 17: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 17

Example: Abstraction

Student Professor

Course Offering (9:00 a.m., Monday-Wednesday-Friday)

Course (e.g. Algebra)

Page 18: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 18

What Is Encapsulation?

Improves Resiliency

Hides implementation from clients. Clients depend on interface.

Page 19: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 19

Encapsulation Illustrated

Professor Clark needs to be able to teach four classes in the next semester.

Subm

itFin

alG

rade

s()

AcceptCourseOffering()

TakeSabbatical()

Professor Clark

SetMaxLoad()

Name: J Clark

Employee ID: 567138

HireDate: 07/25/1991

Status: Tenured

Discipline: Finance

MaxLoad:4SetMaxLoad(4)

Page 20: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 20

What Is Modularity?

Breaks up something complex into manageable pieces.

Helps people understand complex systems.

Page 21: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 21

Example: Modularity

For example, break complex systems into smaller modules. Billing

System

Course Registration System

Course Catalog System

Student Management System

Page 22: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 22

What Is Hierarchy?

Decreasing abstraction

Increasingabstraction

Asset

RealEstate

Savings

BankAccount

Checking Stock

Security

Bond

Elements at the same level of the hierarchy should be at the same level of abstraction.

Page 23: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 23

Representing Objects in the UML

An object is represented as a rectangle with an underlined name.

J Clark : Professor

: Professor

Named Object

Anonymous Object

Professor J Clark

Page 24: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 24

What Is a Class?

A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics. An object is an instance of a class.

A class is an abstraction in that it Emphasizes relevant characteristics. Suppresses other characteristics.

Page 25: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 25

A Sample Class

ClassCourse

PropertiesName

LocationDays offeredCredit hours

Start timeEnd time

BehaviorAdd a student

Delete a studentGet course roster

Determine if it is full

Page 26: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 26

Representing Classes in the UML

A class is represented using a rectangle with compartments.

Professor J Clark

Professor

- name- employeeID : UniqueId- hireDate- status- discipline- maxLoad

+ submitFinalGrade()+ acceptCourseOffering()+ setMaxLoad()+ takeSabbatical()

Page 27: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 27

Class Compartments

A class has three sections: The class name The structure (attributes) The behavior (operations)

Professor

- name- employeeID : UniqueId- hireDate- status- discipline- maxLoad

+ submitFinalGrade()+ acceptCourseOffering()+ setMaxLoad()+ takeSabbatical()

Page 28: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 28

The Relationship between Classes and Objects

A class is an abstract definition of an object. It defines the structure and behavior of each

object in the class. It serves as a template for creating objects.

Classes are not collections of objects.

Professor

Professor Meijer

Professor Torpie

Professor Allen

Page 29: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 29

What Is an Attribute?

An attribute is a named property of a class that describes the range of values that instances of the property may hold. A class may have any number of attributes or no

attributes at all.

Attributes

Student

- name- address- studentID- dateOfBirth

Page 30: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 30

Attributes in Classes and Objects

name: D. Hatcher

address: 456 Oak

studentID: 2

dateofBirth: 12/11/1969

name: M. Modano

address: 123 Main

studentID: 9

dateofBirth: 03/10/1967

Class

Objects

Student- name- address- studentID- dateOfBirth

Page 31: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 31

What Is an Operation?

A service that can be requested from an object to effect behavior. An operation has a signature, which may restrict the actual parameters that are possible.

A class may have any number of operations or none at all.

Operations

Student

+ get tuition()+ add schedule()+ get schedule()+ delete schedule()+ has prerequisites()

Page 32: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 32

What Is Polymorphism?

The ability to hide many different implementations behind a single interface.

Manufacturer AManufacturer B Manufacturer C

OO Principle:Encapsulation

Page 33: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 33

Example: Polymorphism

Stock Bond Mutual Fund

getCurrentValue()

financialInstrument.getCurrentValue()

getCurrentValue()

getCurrentValue()

Page 34: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 34

What Is Generalization?

A relationship among classes where one class shares the structure and/or behavior of one or more classes.

Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses. Single inheritance. Multiple inheritance.

Is an “is a kind of” relationship.

Page 35: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 35

Example: Single Inheritance

One class inherits from another.

CheckingSavings

Superclass (parent)

Subclasses(children)

Generalization Relationship

Ancestor

Account

- balance- name- number

+ withdraw()+ createStatement()

Descendent

Page 36: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 36

Example: Multiple Inheritance

A class can inherit from several other classes.

Use multiple inheritance only when needed and always with caution!

FlyingThing Animal

HorseWolfBirdHelicopterAirplane

Multiple Inheritance

Page 37: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 37

What Is Inherited?

Inheritance leverages the similarities among classes.

A subclass inherits its parent’s attributes, operations, and relationships.

A subclass may: Add additional attributes, operations,

relationships. Redefine inherited operations. (Use caution!)

Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy.

Page 38: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 38

A general purpose mechanism for organizing elements into groups.

A model element that can contain other model elements.

A package can be used: To organize the model under development. As a unit of configuration management.

What Is a Package?

University

Artifacts

Page 39: Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Introduction to Object Technology

Object Oriented Analysis and Design 39

A Package Can Contain Classes

The package, University Artifacts, contains one package and five classes.

University Artifacts

CourseOffering

Schedule

Professor

Course

Student

Student Artifacts