Vous êtes sur la page 1sur 42

Object Oriented Analysis and Design

Using the UML

Introduction to Object Orientation


(abbreviated!)

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

Objectives: Introduction to Object Orientation


Understand the basic principles 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

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

1. Basic Principles of Object Orientation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

Know This.
3

Hierarchy

Modularity

Encapsulation

Abstraction

Object Orientation

What is Abstraction?

Salesperson
Not saying
which
salesperson
just a
salesperson
in general!!!
Product

Customer

Manages Complexity
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

What is Encapsulation?
Hide implementation from clients
Clients depend on interface only!
Clients do not need to know how the server
operates or provides the services!

How does an object encapsu


What does it encapsulate?
DISCUSS!!!!!

Improves Resiliency
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

What is Modularity?
The breaking up of something complex into
manageable pieces
Order
Entry
Order Processing
System

Order
Fulfillment

Billing
Manages Complexity
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

What is Hierarchy?
Asset

Levels of abstraction

Increasing
abstraction

Security

BankAccount

Savings Checking
Decreasing
abstraction

Stock

Bond

Elements at the same level of the hierarchy


should be at the same level of abstraction

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

RealEstate

2. Basic Concepts of Object Orientation


Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

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

Know This.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

Representing Objects the beginnings


An object is represented as a rectangle with
underlined name (no class name shown here)
: Professor

(unnamed object)

a + b = 10

ProfessorClark
Class Name Only

ProfessorClark :
Professor

Professor Clark

Object Name Only

Class and Object Name


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

(stay tuned for classes)


10

What is a Class?
A class is a description of a group of
objects with common properties (attributes),
behavior (operations), relationships, and
semantics
A class is an abstraction of objects.
An object is an instance of a class

OO Principle: Abstraction
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

11

Representing Classes
A class is represented using a
compartmented rectangle
(note: no underlining)

a + b = 10

Professor

Professor Clark

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

12

Class Compartments a bit more development


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)
Class Name
Attributes
Operations

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

Professor
name
empID
create( )
save( )
delete( )
change( )
13

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

Class

Professor
Professor Smith

Professor Mellon

Professor Jones
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

14

What is an Attribute?
Object

Class
Attribute

CourseOffering

Specific
attribute values
for different
objects

number
startTime
endTime

:CourseOffering
number = 101
startTime = 900
endTime = 1100

:CourseOffering
number = 104
startTime = 1300
endTime = 1500

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

15

What is an Operation? (very general form here)

CourseOffering
Class

Operation

addStudent
deleteStudent
getStartTime
getEndTime

Really need to show more, but here, this is sufficient.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

16

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 welldefined architecture
A component may be
A source code component
A run time component or
An executable component
Source File
Name

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

<<EXE>>
Executable
Name

17

OO Principle:
Encapsulation

Component
Interface

<<DLL>>
Component
Name

What is a Package?
A package is a general purpose mechanism for organizing like
elements into groups
A model element which can contain other model elements
Think: in the Java API, similar classes are found in packages that
we may import, etc.

Package Name
Uses
Organize the model under development
A unit of configuration management

OO Principle:
Modularity

Know This

Think: Math class. (contains math classes such as cos() )


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

18

Example for Data Structures Class:


Think IO package you imported.
Inside this package are many (often) unrelated
classes.

FileReader
BufferedReader
FileWriter
PrinterWriter, etc.

To USE any of these classes, we merely create an


object of them and proceed independently of
any other classes.
To USE any of these classes in the package, we
go directly to the class, instantiate the class, and
use the methods in the objects.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

19

What is a Subsystem?
A combination of a package (contains other model
elements) and a class (has behaviors)
A subsystem: realizes one or more interfaces which
define its behavior
Interface is an abstract class. Subsystems
implement (realize) the interface(s)
Realization

<<subsystem>>
Subsystem Name

Interface

Subsystem

Interface

OO Principles: Encapsulation and Modularity

Know This.(stay tuned for realization relationship)


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

20

Example of Subsystems
Realization

<<subsystem>>
Subsystem Name

Interface

Subsystem

Interface
Subsystem might be AccountsReceivable, AccountsPayable, Billing,
That is, a major hunk of functionality.

BUT, a client of the subsystem does NOT have access to the individu
Classes like in a Package. Rather, a client must go through the
public Interface to the subsystem, which contains the signatures of t
services provided within the subsystem.
The contents of the subsystem are NOT directly accesses;
They are protected;
Only the services shown in the interface are made available to clien
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

21

Relationships
Association
Aggregation
Composition

Dependency
Generalization
Realization

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

22

Relationships: Association

Models a semantic connection among classes


Association Name

Professor

University

Works for

Association
Class

Role Names

University

Professor
Employee

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

23

Employer

Relationships: Aggregation (simple aggregate)


A special form of association that models a
whole-part relationship between an
aggregate (the whole) and its parts
Whole

Part

Schedule

Student

Know This
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

Aggregation sometimes called


simple aggregation.
This is sometimes called a
has_a relationship
24

Relationships: Composition
A form of aggregation with strong
ownership and coincident lifetimes
The parts cannot survive the whole/aggregate
Part

Whole

Schedule

Student

Know This
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

Aggregation
This one is called
composition.
25

Association: Multiplicity and Navigation


Multiplicity defines how many objects participate
in a relationship
Multiplicity is a Structural Relationship!
The number of instances (that is, objects) of one
class related to ONE instance of another class
(examples ahead)
Specified for each end of the association

Associations and aggregations are


bidirectional 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
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

26

Association: Multiplicity
Unspecified
Exactly one
1
Zero or more (many, unlimited) 0..*
*

One or more
Zero or one
Specified range
Multiple, disjoint ranges
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

27

1..*
0..1
2..4
2, 4..6

Example: Multiplicity and Navigation

Multiplicity

Student

0..*

Schedule

Navigation

Note: A student has zero or more schedules. (Multiplicity)


Note:

Aggregation: has_a (whole-part relatio

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

28

Relationships: Dependency

A relationship between two model elements where a


change in one may cause a change in the other
Non-structural, using (or communicates) relationship
(non-structural: no numbers of one kind related to another kind)

Can actually say the Client uses the Supplier.

Know This

Client

Class

Package

Supplier

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

Supplier

Client

Dependency
relationship

ClientPackage

Component

SupplierPackage

29

Dependency
relationship

Relationships: 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
Generalization is a is-a-kind of
relationship, or simply, is_a relationship.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

30

Example: Single Inheritance


One class inherits from another
Ancestor

Account
balance
name
number

Superclass
(parent)

Withdraw()
CreateStatement()

Generalization Relationship

Savings

Checking

Subclasses

GetInterest()

Withdraw()

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

Withdraw()

Descendents
31

Subclasses inherit both


attributes and methods from
base (parent) class.

Example: Multiple Inheritance


A class can inherit from several other classes
FlyingThing

Animal
multiple
inheritance

Airplane

Helicopter

Bird

Wolf

Horse

Use multiple inheritance only when needed, and


always with caution !
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

32

What Gets Inherited?


A subclass inherits its parents 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
Inheritance leverages the similarities among classes
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

33

Example: What Gets Inherited (note form of arrow)

GroundVehicle

Superclass
(parent)

owner

weight
licenseNumber

0..*

Person

register( )

generalization

Subclass

Truck

Car
size

tonnage
getTax( )

What about a register() in Car?


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

34

Trailer

Relationships: Realization (note form of arrow)


One classifier serves as the contract that the
other classifier agrees to carry out
Found between:
Interfaces and the classifiers that realize them

Subsystem
Interface

Canonical form

Use Case
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

Elided form

Use-Case Realization
35

Introduction to Object Orientation Topics


Basic Principles of Object Orientation
Basic Concepts of Object Orientation
Strengths of Object Orientation
General UML Modeling Mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

37

4. Stereotypes
Classify/extend 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

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

38

Notes
A Note can be added to any UML element
The class diagram is the one most often
extended

Notes may be added to add more info to


diagram
It is a dog eared rectangle
The note may be anchored to an element with
There can be up to one
a dashed line
MaintainScheduleForm per
user session.

MaintainScheduleForm

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

39

Tagged Values
Extensions of the properties, or specific
attributes, of a UML element
Some properties are defined by UML
Persistence
Location (e.g., client, server)

Properties can be created by UML


modelers for any purpose
PersistentClass
{persistence}

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

anObject : ClassA
{location=server}

40

Constraints
Supports the addition of new rules or
modification of existing rules

Professor

Member

1..*
Department Head
1

Department

{subset}
1

This notation is used to capture two relationships between Professor-t


and Department-type objects; where one relationship is a subset of

Shows how UML can be tailored to correctly modeling exact relationsh

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

41

Review: Introduction to Object Orientation


What are the four basic principles of object
orientation?
Provide a brief description of each.

What is an Object and what is a Class?


What is the difference between them?

What is an Attribute?
What is an Operation?
What is an Interface?
What is Polymorphism?
What is a Component?
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright 1998-1999 Rational Software, all rights reserved

42

(continued)

Review: Introduction to Object Orientation (cont.)


What is a Package?
What is Subsystem?

Know This

How does it relate to a Component?


How does it relate to a package?
How does it relate to a class?

Name the four basic UML relationships and describe


each.
Describe the strengths of object orientation.
Name and describe some general UML mechanisms.
What are stereotypes?
Name some common uses of stereotypes.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright 1998-1999 Rational Software, all rights reserved

43

Vous aimerez peut-être aussi