You are on page 1of 61

Basic Concepts of Object

Oriented Analysis and Design

1 Object Oriented Analysis and Design and UML 11/6/2010


Objectives: Introduction to Object
2
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

Object Oriented Analysis and Design and UML 11/6/2010


Introduction to Object Orientation
3
Topics
 Basic Principles of Object Orientation
 Basic Concepts of Object Orientation
 Strengths of Object Orientation
 General UML Modeling Mechanisms

Object Oriented Analysis and Design and UML 11/6/2010


Object-Oriented Overview
22-4

 Object-oriented techniques work well in situations


where complicated systems are undergoing
continuous maintenance, adaptation, and design
 There are two ways to model object-oriented
systems
 Coad and Yourdon methodology
 The Unified Modeling Language

Object Oriented Analysis and Design and UML 11/6/2010


Object-Oriented Programming
22-5

 Six ideas characterize object-oriented


programming:
 An object, which represents a real-world thing or event
 A class, or group of related objects

 Messages, sent between objects

 Encapsulation, only an object makes changes through its


own behavior

Object Oriented Analysis and Design and UML 11/6/2010


Object-Oriented Programming
22-6

 Six ideas characterize object-oriented


programming (continued):
 Inheritance,
a new class created from another class
 Polymorphism, meaning that a derived class behavior
may be different from the base class

Object Oriented Analysis and Design and UML 11/6/2010


Terminology
22-7

 Class refers to a template for a group of individual


objects with common attributes and common
behavior
 The difference between an Object and a Class is
that the class defines shared attributes and
behaviors of objects
 An object is an instance or occurrence of a class

Object Oriented Analysis and Design and UML 11/6/2010


Terminology
22-8

 Another name for property is attribute


 Another name for method is operation
 Interface means the behavior of a class or
component that is noticeable from outside the
class or component

Object Oriented Analysis and Design and UML 11/6/2010


Basic Principles of Object Orientation
9

Object Orientation

Encapsulation
Abstraction

Modularity

Hierarchy
Object Oriented Analysis and Design and UML 11/6/2010
What is Abstraction?
10

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

Manages Complexity

Object Oriented Analysis and Design and UML 11/6/2010


Abstraction
11 A mental ability that permits people to view real-world
problem domains with varying degrees of detail
depending on the current context of the problem.

• Helps people to think about what they are doing


• Functional and Data abstraction
Object Oriented Analysis and Design and UML 11/6/2010
Encapsulation (Information Hiding)
12 A technique in which data are packaged together
with their corresponding procedures.

 In Object-Oriented Technology the “package” is called an OBJECT


 The interface to each object is defined in such a way as to reveal as
little as possible about its inner workings
 Encapsulation allows [software] changes to be reliably made with
limited effort [Gannon, Hamlet, & Mills, 1987]
One cake please! Ingredients cake
2 eggs 4 cups flour
1 cup milk 1 cup sugar
etc.......

Directions
Pre-heat oven to 350; Put
Object Oriented Analysis
milk, eggs,and Design and UML
and sugar 11/6/2010
in 2 quart mixing bowl...
Encapsulation
22-13

 How does an object encapsulate?


 What does it encapsulate?
 Encapsulation changes the manner in which data is
updated by programs because data can only be
changed via the services that encapsulate the data
 Hide implementation from clients
 Clients depend on interface

Object Oriented Analysis and Design and UML 11/6/2010


What is Modularity?
14

 The breaking up of something complex into


manageable pieces Order
Entry

Order Processing
System Order
Fulfillment

Billing

Manages Complexity
Object Oriented Analysis and Design and UML 11/6/2010
Inheritance
15 A mechanism for expressing similarity
between things thus simplifying their
definition.

Inheritance
Person

Student Faculty Staff

• looks
• behavior
• attitudes
• etc... Object Oriented Analysis and Design and UML 11/6/2010
Inheritance
22-16

 The two types of classes are involved in any


inheritance relationship are the base class and the
derived class
 Multiple inheritance means there will be multiple
occurrences of the base type of class in the
inheritance relationship
 Polymorphism only occurs where there is inheritance

Object Oriented Analysis and Design and UML 11/6/2010


What is Hierarchy?
Asset
17
 Levels of abstraction
Increasing
abstraction

BankAccount Security RealEstate

Savings Checking Stock Bond

Decreasing Elements at the same level of the hierarchy


abstraction should be at the same level of abstraction
Object Oriented Analysis and Design and UML 11/6/2010
Introduction to Object Orientation
18
Topics
 Basic Principles of Object Orientation
 Basic Concepts of Object Orientation
 Strengths of Object Orientation
 General UML Modeling Mechanisms

Object Oriented Analysis and Design and UML 11/6/2010


Basic Concepts of Object Orientation
19

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

Object Oriented Analysis and Design and UML 11/6/2010


What is an Object?
22-20

 Informally, an object represents an entity, either


physical, conceptual, or software
 Physical entity
 Conceptual entity
 Software entity
 There are five general types of objects:
 Tangible things
 Roles
 Incidents
 Interactions
 Specifications details

Object Oriented Analysis and Design and UML 11/6/2010


A More Formal Definition
21

 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

Object Oriented Analysis and Design and UML 11/6/2010


Basic Concepts of Object Orientation
22

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

Object Oriented Analysis and Design and UML 11/6/2010


What is a Class?
23

 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
Object Oriented Analysis and Design and UML 11/6/2010
Representing Classes
24

 A class is represented using a compartmented


rectangle

a + b = 10
Professor

Professor Clark

Object Oriented Analysis and Design and UML 11/6/2010


Class Compartments
25

 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 Professor


name
Attributes empID
Operations create( )
save( )
delete( )
change( )
Object Oriented Analysis and Design and UML 11/6/2010
Classes of Objects
26

 How many classes do you see?

Object Oriented Analysis and Design and UML 11/6/2010


The Relationship Between Classes and
27
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 are grouped into classes


Objects Class

Professor

Professor Smith Professor Mellon

Professor Jones
Object Oriented Analysis and Design and UML 11/6/2010
Basic Concepts of Object Orientation
28

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

Object Oriented Analysis and Design and UML 11/6/2010


What is an Attribute?
29
Object
Class

Attribute Attribute Value


:CourseOffering
number = 101
startTime = 900
CourseOffering endTime = 1100
number
startTime
endTime :CourseOffering
number = 104
startTime = 1300
endTime = 1500

Object Oriented Analysis and Design and UML 11/6/2010


Basic Concepts of Object Orientation
30

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

Object Oriented Analysis and Design and UML 11/6/2010


What is an Operation?
31

CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime

Object Oriented Analysis and Design and UML 11/6/2010


Basic Concepts of Object Orientation
32

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

Object Oriented Analysis and Design and UML 11/6/2010


• Polymorphism (“many forms”)
33 The ability to hide different implementations
behind a common interface.
The ability for two or more objects to respond
to the same request, each in its own way.

 H O = water, ice, steam (liquid, solid, vapor)


2

Door
#1
#2
#3
Door Door Door versus
#1 #2 #3
Object Oriented Analysis and Design and UML 11/6/2010
What is Polymorphism?
34
 The ability to hide many different implementations
behind a single interface

Manufacturer B
Manufacturer A Manufacturer C

OO Principle:
Encapsulation

Object Oriented Analysis and Design and UML 11/6/2010


What is an Interface?
35
 Interfaces formalize polymorphism
 Interfaces support “plug-and-play” architectures
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate Cube

Realization relationship (stay tuned for realization relationships)


Object Oriented Analysis and Design and UML 11/6/2010
Basic Concepts of Object Orientation
36

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

Object Oriented Analysis and Design and UML 11/6/2010


What is a Component?
37

 A non-trivial, nearly independent, and replaceable


part of a system that fulfills a clear function in the
context of a well-defined architecture
 A component may be
 A source code component
OO Principle:
Encapsulation
A run time components or
 An executable component

Source File <<EXE>> <<DLL>>


Name Executable Component
Name Component Name
Interface
Object Oriented Analysis and Design and UML 11/6/2010
Basic Concepts of Object Orientation
38

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

Object Oriented Analysis and Design and UML 11/6/2010


What is a Package?
39

 A package is a general purpose mechanism for


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

OO Principle:
Package Name Modularity

 Uses
 Organize the model under development
 A unit of configuration management

Object Oriented Analysis and Design and UML 11/6/2010


Basic Concepts of Object Orientation
40

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

Object Oriented Analysis and Design and UML 11/6/2010


What is a Subsystem?
41

 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>>
Interface Subsystem Name
Interface

OO Principles: Encapsulation and Modularity


(stay tuned for realization relationship)
Object Oriented Analysis and Design and UML 11/6/2010
Subsystems and Components
42

 Components are the physical realization of an


abstraction in the design
 Subsystems can be used to represent the component in
the designDesign Model Implementation Model

<<subsystem>> Component
Component Name Name
Component Component
Interface Interface

OO Principles: Encapsulation and Modularity


Object Oriented Analysis and Design and UML 11/6/2010
Basic Concepts of Object Orientation
43

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

Object Oriented Analysis and Design and UML 11/6/2010


Relationships
44

 Association
 Aggregation

 Composition

 Dependency
 Generalization
 Realization

Object Oriented Analysis and Design and UML 11/6/2010


Relationships: Association
45

 Models a semantic connection among classes


Association Name

Professor Works for University

Association
Role Names

Class University
Professor
Employee Employer

Object Oriented Analysis and Design and UML 11/6/2010


Relationships: Aggregation
46

 A special form of association that models a


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

Student Schedule

Aggregation

Object Oriented Analysis and Design and UML 11/6/2010


Relationships: Composition
47

 A form of aggregation with strong ownership


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

Student Schedule

Aggregation

Object Oriented Analysis and Design and UML 11/6/2010


Association: Multiplicity and Navigation
48

 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
 Ifnavigation is restricted, an arrowhead is added to
indicate the direction of the navigation

Object Oriented Analysis and Design and UML 11/6/2010


Association: Multiplicity
49
 Unspecified
 Exactly one 1

 Zero or more (many, unlimited) 0..*

 One or more *

 Zero or one 1..*

 Specified range 0..1

 Multiple, disjoint ranges 2..4

2, 4..6

Object Oriented Analysis and Design and UML 11/6/2010


Example: Multiplicity and Navigation
50

Multiplicity

Student 1 0..* Schedule

Navigation

Object Oriented Analysis and Design and UML 11/6/2010


Relationships: Dependency
51
 A relationship between two model elements where a
change in one may cause a change in the other
 Non-structural, “using” relationship

Client Supplier Component


Class

Package Client Supplier


Dependency
relationship

ClientPackage SupplierPackage
Dependency
relationship
Object Oriented Analysis and Design and UML 11/6/2010
Relationships: Generalization
52

 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

Object Oriented Analysis and Design and UML 11/6/2010


Example: Single Inheritance
53
 One class inherits from another
Ancestor

Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalization
Relationship

Checking Savings

Subclasses Withdraw() GetInterest()


Withdraw()

Descendents
Object Oriented Analysis and Design and UML 11/6/2010
Example: Multiple Inheritance
54

 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 !
Object Oriented Analysis and Design and UML 11/6/2010
What Gets Inherited?
55

 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

Inheritance leverages the similarities among classes


Object Oriented Analysis and Design and UML 11/6/2010
Example: What Gets Inherited
56

GroundVehicle
owner Person
Superclass weight
(parent) licenseNumber 0..* 1

register( )
generalization

Car Truck Trailer


Subclass size tonnage
getTax( )

Object Oriented Analysis and Design and UML 11/6/2010


Relationships: Realization
57
 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 CaseObject Oriented Analysis and Design and UML


Use-Case Realization
11/6/2010
Introduction to Object Orientation
58
Topics
 Basic Principles of Object Orientation
 Basic Concepts of Object Orientation
 Strengths of Object Orientation
 General UML Modeling Mechanisms

Object Oriented Analysis and Design and UML 11/6/2010


Strengths of Object Orientation
59

 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
Object Oriented Analysis and Design and UML 11/6/2010
Class Diagram for the Sales Example
60

Sale

seller buyer item sold shipping mechanism


Salesperson Customer Product Vehicle

Corporate Individual Truck Train

Object Oriented Analysis and Design and UML 11/6/2010


Effect of Requirements Change
61
Suppose you need a
Sale
new type of shipping
vehicle ...

seller buyer item sold shipping mechanism


Salesperson Customer Product Vehicle

Corporate Individual Truck Train Airplane

Change involves adding a new subclass


Object Oriented Analysis and Design and UML 11/6/2010

You might also like