You are on page 1of 59

www.gupshupstudy.

com

Object Oriented Analysis and Design

Introduction to Object Orientation

GupShupStudy.com 1

Objectives: Introduction to Object Orientation


www.gupshupstudy.com

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

GupShupStudy.com 2

Introduction to Object Orientation Topics


www.gupshupstudy.com

Basic Principles of Object Orientation


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

GupShupStudy.com 3

Basic Principles of Object Orientation


www.gupshupstudy.com

Hierarchy

Modularity

Encapsulation

Abstraction

Object Orientation

GupShupStudy.com 4

What is Abstraction?
www.gupshupstudy.com

Salesperson
Not saying
Which
salesperson
just a
salesperson
in general!!!
Customer

Product

Manages Complexity
5

GupShupStudy.com 5

What is Encapsulation?
www.gupshupstudy.com

Hide implementation from clients


Clients depend on interface

How does an object encapsulate?


What does it encapsulate?

Improves Resiliency
6

GupShupStudy.com 6

What is Modularity?
www.gupshupstudy.com

The breaking up of something complex into


manageable pieces
Order
Entry
Order Processing
System

Order
Fulfillment

Billing
Manages Complexity
7

GupShupStudy.com 7

What is Hierarchy?
www.gupshupstudy.com

Levels of abstraction

Asset

Increasing
abstraction

Security

BankAccount

Savings Checking
Decreasing
abstraction

Stock

RealEstate

Bond

Elements at the same level of the hierarchy


should be at the same level of abstraction
8

GupShupStudy.com 8

Introduction to Object Orientation Topics


www.gupshupstudy.com

Basic Principles of Object Orientation


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

GupShupStudy.com 9

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
10

GupShupStudy.com 10

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
11

GupShupStudy.com 11

What is an Object?
www.gupshupstudy.com

Informally, an object represents an entity,


either physical, conceptual, or software
Physical entity
Truck

Conceptual entity
Chemical Process

Software entity

Linked List

12

GupShupStudy.com 12

A More Formal Definition


www.gupshupstudy.com

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

13

GupShupStudy.com 13

Representing Objects
www.gupshupstudy.com

An object is represented as rectangles with


underlined names
: Professor
a + b = 10

ProfessorClark
Class Name Only
Professor Clark

ProfessorClark :
Professor

Object Name Only

Class and Object Name

(stay tuned for classes)


14

GupShupStudy.com 14

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
15

GupShupStudy.com 15

What is a Class?
www.gupshupstudy.com

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

OO Principle: Abstraction
16

GupShupStudy.com 16

Sample Class
www.gupshupstudy.com

Class
Course
Properties
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

a + b = 10

17

GupShupStudy.com 17

Representing Classes
www.gupshupstudy.com

A class is represented using a


compartmented rectangle

a + b = 10

Professor
Professor Clark

18

GupShupStudy.com 18

Class Compartments
www.gupshupstudy.com

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

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

19

GupShupStudy.com 19

Classes of Objects
www.gupshupstudy.com

How many classes do you see?

20

GupShupStudy.com 20

The Relationship Between Classes and Objects


www.gupshupstudy.com

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 are grouped into classes


Class

Objects

Professor
Professor Smith

Professor Mellon

Professor Jones
21

GupShupStudy.com 21

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
22

GupShupStudy.com 22

What is an Attribute?
www.gupshupstudy.com

Object

Class
Attribute

Attribute Value

:CourseOffering

CourseOffering

number = 101
startTime = 900
endTime = 1100

number
startTime
endTime

:CourseOffering
number = 104
startTime = 1300
endTime = 1500

23

GupShupStudy.com 23

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
24

GupShupStudy.com 24

What is an Operation?
www.gupshupstudy.com

CourseOffering
Class

Operation

addStudent
deleteStudent
getStartTime
getEndTime

25

GupShupStudy.com 25

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
26

GupShupStudy.com 26

What is Polymorphism?
www.gupshupstudy.com

The ability to hide many different


implementations behind a single interface

Manufacturer A

Manufacturer B

Manufacturer C

OO Principle:
Encapsulation
27

GupShupStudy.com 27

What is an Interface?
www.gupshupstudy.com

Interfaces formalize polymorphism


Interfaces support plug-and-play
architectures
Tube
<<interface>>

Shape
Pyramid
Draw
Move
Scale
Rotate

Cube

Realization relationship
28

(stay tuned for realization relationships)


GupShupStudy.com 28

Interface Representations
www.gupshupstudy.com

Tube

Elided/Iconic
Representation
(lollipop)

Pyramid

Shape

Canonical
(Class/Stereotype)
Representation

Cube

Tube
<<interface>>

Shape

Pyramid

Draw
Move
Scale
Rotate

Cube
29

GupShupStudy.com 29

(stay tuned for realization relationships)

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
30

GupShupStudy.com 30

What is a Component?
www.gupshupstudy.com

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 components or
An executable component
Source File
Name

<<EXE>>
Executable
Name

31

OO Principle:
Encapsulation

Component
Interface

<<DLL>>
Component
Name
GupShupStudy.com 31

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
32

GupShupStudy.com 32

What is a Package?
www.gupshupstudy.com

A package is a general purpose mechanism


for organizing elements into groups
A model element which can contain other
model elements

Package Name

OO Principle:
Modularity

Uses
Organize the model under development
A unit of configuration management
33

GupShupStudy.com 33

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
34

GupShupStudy.com 34

What is a Subsystem?
www.gupshupstudy.com

A combination of a package (can contain


other model elements) and a class (has
behavior)
Realizes one or more interfaces which
define its behavior
Realization

Subsystem

<<subsystem>>
Subsystem Name

Interface

Interface

OO Principles: Encapsulation and Modularity


(stay tuned for realization relationship)
35

GupShupStudy.com 35

Subsystems and Components


www.gupshupstudy.com

Components are the physical realization of


an abstraction in the design
Subsystems can be used to represent the
component in the design
Design Model

Implementation Model

Component
Name

<<subsystem>>
Component Name

Component
Interface

Component
Interface

OO Principles: Encapsulation and Modularity


36

GupShupStudy.com 36

Basic Concepts of Object Orientation


www.gupshupstudy.com

Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
37

GupShupStudy.com 37

Relationships
www.gupshupstudy.com

Association
Aggregation
Composition

Dependency
Generalization
Realization

38

GupShupStudy.com 38

Relationships: Association
www.gupshupstudy.com

Models a semantic connection among


classes
Association Name

Professor

University

Works for

Association
Class

Role Names

University

Professor
Employee
39

Employer
GupShupStudy.com 39

Relationships: Aggregation
www.gupshupstudy.com

A special form of association that models a


whole-part relationship between an
aggregate (the whole) and its parts
Whole

Part

Schedule

Student

Aggregation

40

GupShupStudy.com 40

Relationships: Composition
www.gupshupstudy.com

A form of aggregation with strong


ownership and coincident lifetimes
The parts cannot survive the whole/aggregate
Part

Whole

Schedule

Student

Aggregation

41

GupShupStudy.com 41

Association: Multiplicity and Navigation


www.gupshupstudy.com

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 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
42

GupShupStudy.com 42

Association: Multiplicity
www.gupshupstudy.com

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

One or more
Zero or one
Specified range
Multiple, disjoint ranges

43

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

GupShupStudy.com 43

Example: Multiplicity and Navigation


www.gupshupstudy.com

Multiplicity

Student

0..*

Schedule

Navigation

44

GupShupStudy.com 44

Relationships: Dependency
www.gupshupstudy.com

A relationship between two model elements


where a change in one may cause a
change in the other
Non-structural, using relationship
Client

Class

Package

ClientPackage

Supplier

Component

Supplier

Client

Dependency
relationship

SupplierPackage

Dependency
relationship
45

GupShupStudy.com 45

Relationships: Generalization
www.gupshupstudy.com

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

Generalization is an is-a-kind of
relationship

46

GupShupStudy.com 46

Example: Single Inheritance


www.gupshupstudy.com

One class inherits from another


Ancestor

Superclass
(parent)

Account
balance
name
number
Withdraw()
CreateStatement()

Generalization
Relationship

Subclasses

Checking

Savings

Withdraw()

GetInterest()
Withdraw()

Descendents
47

GupShupStudy.com 47

Example: Multiple Inheritance


www.gupshupstudy.com

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 !
48

GupShupStudy.com 48

What Gets Inherited?


www.gupshupstudy.com

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
49

GupShupStudy.com 49

Example: What Gets Inherited


www.gupshupstudy.com

GroundVehicle

Superclass
(parent)

weight
licenseNumber

owner
0..*

Person

register( )

generalization

Subclass

Truck

Car
size

Trailer

tonnage
getTax( )

50

GupShupStudy.com 50

Relationships: Realization
www.gupshupstudy.com

One classifier serves as the contract that


the other classifier agrees to carry out
Found between:
Interfaces and the classifiers that realize them
Class

Component

Subsystem
Interface

Interface

Interface

Elided form

Use cases and the collaborations that realize


them
Canonical form

Use Case

Use-Case Realization
51

GupShupStudy.com 51

Class Diagram for the Sales Example


www.gupshupstudy.com

Sale

seller

Salesperson

buyer

item sold

Customer

Corporate

Vehicle

Product

Individual

54

shipping mechanism

Truck

Train

GupShupStudy.com 52

Effect of Requirements Change


www.gupshupstudy.com

Suppose you need a


new type of shipping
vehicle ...

seller

Salesperson

Sale

buyer

item sold

Customer

Corporate

Product

Truck

Individual

shipping mechanism

Vehicle

Train

Airplane

Change involves adding a new subclass


55

GupShupStudy.com 53

Introduction to Object Orientation Topics


www.gupshupstudy.com

Basic Principles of Object Orientation


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

56

GupShupStudy.com 54

Stereotypes
www.gupshupstudy.com

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

57

GupShupStudy.com 55

Example: Stereotypes
www.gupshupstudy.com

<<boundary>>

<<boundary>>
<<trace>>
DesignClass

Sample boundary class (stereotype)


Stereotype of dependency relation
Stereotype of <<Processor>>
These create new symbols using
accustomed graphics.

<<Processor>>
Processor #1

Processor #1

58

GupShupStudy.com 56

Notes

www.gupshupstudy.com

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
There can be up to one
MaintainScheduleForm per
user session.

MaintainScheduleForm

59

GupShupStudy.com 57

Tagged Values
www.gupshupstudy.com

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}

anObject : ClassA
{location=server}

60

GupShupStudy.com 58

Constraints
www.gupshupstudy.com

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-type objects


and Department-type objects; where one relationship is a subset of another.
Shows how UML can be tailored to correctly modeling exact relationships.
61

GupShupStudy.com 59

You might also like