Upload
doankhue
View
215
Download
0
Embed Size (px)
Citation preview
1
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 1
Introduction to Object Orientation
Fall 2003 CSC 532
The material in this powerpoint is originally from Rational company. It has been modified and used as an introduction to RUP as educational purpose only in Advanced Topics in software engineering CSC532
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 2
Objective: Introduction to Object Orientation
• Understand the basic principle of object orientation
• Understand the basic concepts and terms of object orientation and the associated UML notation
• Appreciate the strengths of object orientation• Understand some basic UML modeling
mechanisms
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 3
Introduction to Object Orientation Topics
• Basic Principles of Object Orientation• Basic Concepts of Object Orientation• Strengths of Object Orientation• General UML Modeling Mechanisms
2
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 4
Basic Principles of Object Orientation
Object Orientation
• Abstraction• Encapsulation• Modularity• Hierarchy
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 5
What is Abstraction?
Salesperson
Customer Product
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 6
What is Encapsulation
• Hide implementation from clients• Clients depend on interface
3
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 7
What is Modularity?
• The breaking up of something complex into manageable pieces
Order Processing System
Order Entry
Order Fulfillment
Billing
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 8
What is Hierarchy?
• Level of abstractionIncreasing abstraction
Decreasing Abstraction
Asset
Bank Account Security Real Estate
Savings Checking Stock Bond
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 9
Basic Concepts Of Object Orientation• Object• Class• Attributes• Operation• Interface (Polymorphism)• Components• Package• Subsystem• Relationships
4
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 10
What is an Object?
• Informally, an object represents an entity, either physical, conceptual, or software• Physical entity
• Conceptual entity
• Software entity
truck
Chemical Process
Linked List
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 11
A More Formal Definition
• An object is a concept, abstraction, or thing with sharp boundaries and meaning for an application
• An object is something that has• State• Behavior• Identity
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 12
An Object Has State (stop here)
• The state of an object is one of the possible conditions in which an object may exist
• The state of an object normally changes over time
• Represented by: Attribute values + Links (relationship instances)
Professor Clark
Name
Employee ID
Date hired
Status
Joy Clark
567138
March 21, 1987
Tenured
5
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 13
An Object Has Behavior
• Behavior determines how an object acts and reacts to requests from other objects
• Behavior is represented by the set of messages it can respond to (the operations the object can perform)
Registration System
Assign Prof. Clark(Returns: conformation)
Algebra 101 Course
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 14
An Object Has Identity
• Each object has a unique identity, even if its state is identical to that of another object
Prof. “J. Clark” Teaches algebra
Prof. “J. Clark” Teaches algebra
Prof. “J. Clark” Teaches algebra
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 15
Representing Objects
• An object is represented as rectangles with underlined names
: Professor
ProfessorClark : Professor
Class Name Only
Class and Object Name
ProfessorClark
Object Name Only
6
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 16
Example: Objects
Intro to OO 180
Algebra 110
World History 200
Music History 200
Geology 110
Geology 110
English 101
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 17
What is a Class?
• A class is a description of a group of objects with common properties (attributes), behavior (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
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 18
Sample Class•Class
CourseProperties
Name
Location
Days offered
Credit hours
Start time
End time
Behavior
Add a student
Delete a student
Get course roster
Determine if it is full
7
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 19
Representing Classes
• A class is represented using a compartmented rectangle
Professor
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 20
Class Compartments
• A class is comprised of three sections• The first section contains the class name• The second section shows the structure
(attributes)• The third section shows the behavior
(operations) ProfessorName
save()change()
delete()
empIDcreate()
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 21
Class Compartments (cont.)
• The second and third sections may be suppressed if they need not be visible on the diagram
ProfessorName
save()change()
delete()
empIDcreate()
ProfessorName
empID
Professor
save()change()
delete()
create()
Professor
Professor
8
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 22
Example: Class
CourseOffering
Intro to OO 180
Algebra 110
World History 200
English 101
Music History 200
Geology 110
Geology 110
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 23
Classes of Objects
• How many class can you see?
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 24
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
• Objects may be grouped into classesProfessor
Professor Smith Professor Jones Professor Mellon
9
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 25
What is Attribute?
Class
Attribute
CourseOfferingnumber
startTimeendTime
startTime=900
endTime=1100
DS:CourseOffering
Number=110
endTime=1100
startTime=900
startTime=900
Object
Attribute Value
OS:CourseOffering
Number=104
endTime=1500startTime=1300
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 26
What is Operation?
:CourseOffering
addStudentdeleteStudentgetStartTime
getEndTime
Class
Operation
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 27
What is Polymorphism?
• The ability to hide many different implementations behind a single interface
Manufacture A Manufacture B Manufacture C
OO Principle:
Encapsulation
10
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 28
What is an Interface?
• Interface formalize polymorphism• Interface support “plug-and-play”
architecture<<interface>>
Shape
ScaleMove
Rotate
Draw
Tube
Pyramid
Cube
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 29
Interface Representations
<<interface>>
Shape
ScaleMove
Rotate
Draw
Tube
Pyramid
Cube
Canonical
(Class/Stereotype)
presentation
Tube
Pyramid
Cube
Elided/Iconic
Representation
(“lollipop”)
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 30
What is a Component?
• A non-trivial, nearly independent, and replaceable part of a system that fulfills a clear function in the context of a well-defined architecture
11
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 31
What is a Component?(Cont.)
Source File
Name
<<EXE>>
Executable Name
<<DLL>>
Component Name
•A component may be•A source code component
•A run time component or
•An executable component
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 32
Source Code Coponents• Visualize compilation dependencies
between source code files
Account.h
Report.cpp Account.cpp
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 33
Executable and Run-time Components
• Visualizing all of the pieces of an executable release, their interfaces, and their relationships
<<EXE>>
ATM
Bank <<DLL>>
Account
Iaccount Ibank
12
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 34
Interfaces and Components
• Interfaces can be realized by components
Source File
Name
Implementation Model
Component
Interface
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 35
What is a Package?
• A package is a general purpose mechanism for organizing elements into groups
• A model element which can contain other model elements
• Uses• Organize the model under development• A unit of configuration management
Package Name
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 36
What is a Subsystem?
• A “cross between” a package (can contain other model elements) and a class (has behavior)
• Realizes one or more interfaces which define its behavior
<<subsystem>>
Subsystem Nameinterface
RealizationSubsystem
13
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 37
Subsystems and Components
• Components are the physical realization of an abstraction in the design
• Subsystems can be used to represent the component in the design
<<subsystem>>
Component NameCurrent Interface
Design Model
Component Name
Implementation Model
Component Interface
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 38
Relationships
• Association• Aggregation• Composition
• Dependency• Generalization• Realization
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 39
Relationships: Association
• Models a semantic connection among classes
Professor University
Professor University
Association name
Works for
Class Association
Employee Employer
Role Names
14
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 40
Relationship: Aggregation
• A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts
Student Schedule
Aggregation
WholePart
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 41
Relationship: Composition
• A form of aggregation with strong ownership and coincident lifetimes• The parts cannot survive the whole/aggregate
Human Heart
Aggregation
WholePart
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 42
Association: Multiplicity and Navigation
• Multiplicity defines how many objects participate in a relationships• The number of instances of one class related to
ONE instance of the other class• Specified for each end of the association
• Associations and aggregations are bi-directional by default, but it is often desirable to restrict navigation to one direction• If navigation is restricted, an arrowhead is
added to indicate the direction of the navigation
15
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 43
Association: Multiplicity• Unspecified• Exactly one• Zero or more (many, unlimited)
• One or more• Zero or one• Specified range• Multiple, disjoint ranges
1
0..*
*
1..*
0..1
2..4
2,4..6
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 44
Example: Multiplicity and Navigation
Student Schedule
Navigation
0..*1
Multiplicity
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 45
Relationship: Dependency• A relationship between two model elements
where a change in one may cause a change in the other
• None-structural, “using” relationshipClient Supplier
ClientPackage SupplierPackage
Client Supplier
Class
Package Dependency relationship
Component
Dependency relationship
16
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 46
Relationship: 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 super classes– Single inheritance– Multiple inheritance
• Generalization is an “is-a-kind of” relationship
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 47
Example: Single Inheritance• One class inherits from another
Accountbalance
numbername
Withdraw()CreateStatement()
Checking
Withdraw()
Savings
GetInterest()Withdraw()
Subclasses
Superclass
(parent)
Ancestor
Descendents
Generalization Relationship
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 48
Multiple Inheritance
• A class can inherit from several other classes
FlyingThing Animal
Airplane Helicopter Bird Wolf Horse
multiple inheritance
17
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 49
What Gets Inherited?• 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
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 50
Example: What Gets InheritedGroundVehicle
weightlicenseNumberregister()
Person
Carsize
getTax()
Trucktonnage
Trailer
0..* 1owner
Generalization
Superclass
(parent)
Subclasses
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 51
Relationship: Realization• One classifier serves as the contract that the
other classifier agrees to carry out • Found between
– Interfaces and the classifiers that realize them
ClassSubsystem Client
–Use cases and the collaborations that realize them
Elided formInterface Interface Interface
Canonical form
Use Case Use-Case Realization
18
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 52
Strengths of Object Orientation• A single paradigm• Facilitates architectural and code reuse• Models more closely reflect the real world
– More accurately describe corporate data and processes
– Decomposed based on natural partitioning– Easier to understand and maintain
• Stability– A small change in requirements does not mean
massive changes in the system under development
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 53
A simple Sales Order Example
Order
Product
Ship via
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 54
Class Diagram for the Sales Example
Sale
Salesperson Customer VehicleProduct
Corporate Individual Truck Train
seller buyer Item sold Shipping mechanism
19
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 55
Effect of Requirements ChangeSale
Salesperson Customer VehicleProduct
Corporate Individual Truck Train
seller buyer Item sold Shipping mechanism
Airplane
Suppose you need a new type of shipping vehicle …
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 56
Stereotypes• Classify and extend the UML notational
elements• Define a new model element in terms of
another model element• May be applied to all modeling elements• Represented with name in guillemets or as a
different icon<<boundary>>
MyBoundaryClass
MyBoundaryClass
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 57
Example: Stereotypes
<<boundary>>
<<boundary>>
DesignClass
<<trace>>
<<Processor>>Processor #1
<<Processor>>Processor #1
20
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 58
Notes• A note can be added to any UML element• Notes may be added to add more
information to the diagram• It is a ‘dog eared’ rectangle• The note may be anchored to an element
with a dashed line
MaintainScheduleForm
There can be up to one MaintainScheduleForm per user session.
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 59
Properties • A property, or specific attribute, of a UML
element• Also called tagged values• Some properties are defined by UML
– Persistence– Location (e.g., client, server)
• Properties can be created by UML modelers for any purpose
PersistentClass
{persistence}anObject: ClassA
{location=server}
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 60
constraints
• Supports the addition of new rules or modification of existing rules
Professor DepartmentMember
Department Head
11..*
1 1
{subset}
21
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 61
The materials herein are from Rational RSWTL instructor notes handbook. They are copyright of the Rational software. must be used only with education purpose only 62