Unhelkar-POOA-Lecture Notes Chapter

Transcription

Unhelkar-POOA-Lecture Notes Chapter
Module Outline
• Positioning Object Oriented Analysis
• Fundamentals of Object–Orientation
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism
• The need of Modeling
• Unified modeling language
• Mapping the UML to the Modeling Spaces
Fundamentals of Object
Orientation
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
1
What is Object-Oriented?
2
Some Possible Definitions
• A good software engineering practice that
attempts to address new IT challenges
• A good approach to build complex and
rapidly changing software applications in
the new millennium - Therefore, may
apply to “any” software Development
• Encompasses various aspects of software
Development
– Analysis; Design; Implementation; Testing; Metrics;
Databases; Architecture - especially Distributed;
Management;
• Unlike Relational (set) Theory, has no
Mathematical background; hence no
Precise Definition;
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
3
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
4
Accou nt
• OO Software Engineering results in easier
maintainability and extensibility
2000s
Positioning Objects within the
Evolving Technical Thinking
Why Object-oriented?
C us tom er
Account
– Due to Localized and controlled changes
S avin gs
– Code, Design (including Patterns and Frameworks),
Requirements (Use cases), Components (Link time and Run
time)
Booch etc. to Unified
Modeling Language
1980s
• OO Software Engineering results in more
Opportunities for Reuse
C heq u e
1990s
g etI ntere s tD tls ()
Entity-Relationships;
Data Flows;
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
5
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
6
1970s
Flowcharts;
SSADM
1
Positioning Objects
• In 1970’s Flowchart and Structured System
Analysis and Design Methods
• In 1980’s Chen’s popular Entity Relationship
and Data Flow diagrams
• Early 1990’s Unified Modeling Language by
Booch.
+
Global information systems
Distributed
Computing
+
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
7
Learning and Adopting Object
Orientation
Adopting
OO
Web-Services Based Global IT Management
Internet
Technologies
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
8
Sub-Module
Modeling
(UML Standard)
Fundamentals
Global Business
ObjectOrientation
(Components)
Fundamentals of Object
Orientation
Process
Basic Concepts
Experience
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
9
Classes and Objects
10
What is a Class?
• A Class is a DEFINITION, a TEMPLATE, for
the Objects
• NOTE: A Class is NOT a Collection of
Objects;
• A class is not an individual object, represents a
whole set of objects.
A “CLOCK” in general
is a CLASS.
Your CLOCK and
My CLOCK are specific
Objects
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
11
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
12
2
What is an Object?
OO v/s Non-OO (Similarities and
Differences)
• An Entity with crisply defined boundaries
• A physical or conceptual thing in the
problem and the solution domain
• Identity is a unique identifier of an object
• Has attributes that describe the object, and
also describe the state in which it exists
• Has behavior that is manifested in changes
to the state of the object
• Sends and receives messages
Procedures
– Data and Procedures are kept Separate
– Procedures work on Data to produce results
• Object-oriented
Data
– Focus on Responsibilities - to be satisfied
by Objects
– Responsibilities translate into Data and
Functions within a Object
– Objects have Behavior
13
Comparing the Mindsets
Data
Procedures
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
14
The Star of OO Fundamentals
(Henderson-Sellers, Book of OO Knowledge, Prentice-Hall)
OO Mindset
• What is the system
made up of? Objects
• What are the
responsibilities of
these objects?
• How will these objects
collaborate to satisfy
the responsibilities?
• Algorithms/code
deferred
"Copyright Practical OO Analysis,
15
Thomson Publishing, 2005".
Classification
PO
LY
M
CLASSIFICATION
Fundamentals of
Object-Orientation:
THE OBJECT
OR
PH
IS
M
N
IO
CT
RA
ST
AB
Procedural Mindset
• What is the system
supposed to do?
• What are the functions
of the system?
• How do I design and
code to achieve the
functions?
• Focus is on the
algorithms.
EN
CA
PS
UL
AT
IO
N
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
• Non-Object-oriented (Traditional)
E
NC
A
IT
ER
H
IN
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
16
Classification
• Starting point of object orientation
• Grouping meaningful objects.
• Classification is based on the requirements
appearing in the problem space.
Lithops Lesliei
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
17
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
18
3
Abstraction: 1st Level is from Objects to
Class
Abstraction: 2nd Level is from Classes to
Classes
FROG
Can be Abstracted to
ANIMAL
CAT
FROG
Note that these are ABSTRACTIONS and
not real Objects. Objects are Classified
and good Classification leads to creation
of good Abstractions. Classes that
represent a collection of Objects are
Abstract.
HAT
CLOCK
CLOCK
Can be Abstracted to
CAT
Classes are abstracted to higher level class
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
19
BOOK
CHEST
SHOE
HAT
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
21
Identifying more general groupings to
create Inheritance Hierarchy
LIVING
CRANE
FROG
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
22
Inheritance
BIRD and ANIMAL
are types of LIVING things
ANIMAL
20
• Starts by grouping a given set of (reality) Objects
based on certain characteristics
• Example: Marker Pens, Ballpoint Pens etc.
• From the classification (grouping), most common
properties and behavior is abstracted to arrive at a
Class definition
• Infinite number of objects can then be created
(instantiated) from this Class
MAN
Requirements from Problem Space
Can be Classified & Abstracted to
Arrive at Good Classes
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Abstraction (and Classification)..
Classification & Abstraction
BIRD
THING
HAT
MITHU? (my Bird)
PUSPUS? (your Cat)
Are Objects; They
Don’t appear on Class
diagrams
• Inheritance in OO is the ability of a Class to
inherit all attributes and behavior of a
higher-level class
• Classifying with optimum granularity also
leads to good inheritance structure
CAT
23
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
24
4
Inheritance…
Moving on the Inheritance Tree
• Child class inherits from parent class
• Child class shares the attributes and
routines of parent class, plus perhaps adds
additional features
• Child class can change implementation of
parent class features
• multiple inheritance is permitted; some
resolution for name clashes is required
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Finding Superclasses
Needs abstract thinking
Domain knowledge helpful
Essentially FOR Reuse
Finding Subclasses
Concrete lower level
implementation thinking
Essentially WITH Reuse
25
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
26
Encapsulation
Modularity (and Encapsulation)..
Encapsulation means
DATA is accessed only
by METHODS
• When attributes of an Object are NOT
accessed directly by any other Object within
the system but only through the public
interface of the Object, it is Encapsulation
• Objects are modularized to handle complexity,
and encapsulation enhances the advantages by
localizing changes to within the objects
METHODS
BEGIN
DATA
(Attributes
with States)
PUBLIC
VISIBILITY
PRIVATE
INFORMATION
CODE
END
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
27
Polymorphism
On Receipt of Message
move from a Calling
Object, the appropriate
move - depending on whether
it is a Frog or a Horse - will be
executed
HORSE
28
Polymorphism..
ANIMAL
FROG
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
CAT
• Essentially the ability of an Entity to behave
differently - even after receiving the same
message
• Translates to the ability of the software to
substitute different Objects at runtime
• Implemented via Inheritance in Objectorientation
Advantage? CALLING object need not know what is Moved, so, if
a new CAT object is added, the CALLING class doesn’t change
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
29
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
30
5
Purpose of Modelling: Understand and
Create Reality
Sub-Module
(based on Unhelkar, B., 1999, 2003)
Understand
Reality
The Need of Modelling
Software Development Layers
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Create
Reality
31
Modelling and Conceptual Software
Development Layers
(Place of UML)
UML only deals
with Modeling.
It is NOT a
Methodology
(or a Process)
Quality
Environment
QSP; Process
Continuum; Bpwin etc.
RUP, OPEN, MeNtOR
Communication
TauG2; ROSE, Visio.
Technology
Languages, Databases
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Java, C++, XML, Oracle etc.
33
OO Models have a Small Semantic Gap
ANALYSIS
DESIGN
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Class Passenger
Class Flight
Class Seat
Analysis
(MOPS)
Seat
Class Class
Booking Priority
Design
(MOSS)
Class:: Passenger
Class:: Flight
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
34
OO facilitates Seamless Transition from Problem to Solution Space
(from Unhelkar, CRC Press, 1999)
(from Unhelkar, CRC Press, 1999)
Flight
32
Software Development Layers and
Corresponding ‘CASE’ TOOL Layer
Management;
Processes
Modeling
Passenger
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Overall
Management
Methodologies
REALITY
MODEL
MODEL
Class:: Seat
Implementation
(MOSS)
35
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
36
6
Modelling Spaces and Roles in Analysis, Design
and Architecture
(A rough role-based guideline)
!
Sub-Module
"
Model Of Problem
Space (MOPS)
Modeling Spaces
Model Of Background
Space (MOBS)
And Relating them to the UML
!
Model Of Solution
Space (MOSS)
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
37
!
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
38
Workbook Exercises
1.
2.
Exercises
3.
For Classroom
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
4.
5.
39
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
Workbook Exercises
6.
List next to each of the above TWO classes, at least
FIVE attributes.
7. Discuss the importance of each of the fundamentals
of OO within the context of software engineering.
8. What is a process and how it is different from
modeling?
9. What are the two main reasons for creating models?
10. How is object-oriented modeling advantageous?
11. Name the three modeling spaces in OO modeling.
Discuss the advantage of modeling in each of these
three modeling spaces.
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
41
What is object orientation? What does it
encompass?
How is object orientation different from procedural
approach to software development?
What are the four major factors in learning and
adopting object orientation?
List FIVE objects from your current surroundings.
Create at least TWO classes from the above five
objects (This will help you understand the difference
between a class and an object).
40
Conclusions
•
•
•
Software Development benefits with Process and
Modeling; UML is OMG’s standard for Modeling;
OO has Five Fundamentals
Classification; Abstraction; Inheritance;
Encapsulation and Polymorphism
Class is a Template; Object is an Instance;
All Modeling Work happens in 3 Spaces:
MOPS; MOSS; and MOBS
"Copyright Practical OO Analysis,
Thomson Publishing, 2005".
42
7