Upload
mansher
View
218
Download
0
Embed Size (px)
Citation preview
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 1/30
Tech Mahindra Limited confidential© Tech Mahindra Limited 2007
Object Oriented Concepts
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 2/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 2
Objective
At the end of this session, you will be able to:
Introduce Object Oriented Programming
Identify Objects
Design Classes
Understand Object Oriented Concepts
Abstraction
Encapsulation
Inheritance Polymorphism
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 3/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 3
Agenda
Need of Object Oriented Programming
Object
Class
Abstraction
Encapsulation
Inheritance
Polymorphism
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 4/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 4
Introduction
Methodology used for programming is called asProgramming Paradigm
Two Programming Paradigms
Procedure Oriented Programming
Decide which modules you want; partition the program so thatdata is hidden in modules
Importance is given to algorithm rather than data
Object Oriented Programming (OOP) Decide which types you want; provide a full set of operations for
each type
Importance is given to data (Objects) & algorithm supports thedata
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 5/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 510/19/2010 CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited 5
Need of OOP
Procedural ProgrammingLanguages Object Oriented Languages
The unit is a function The unit is a class
Importance is given to the sequenceof tasks to be done
Importance is given to the data.
Larger programs are divided intofunctions
Larger programs are divided intoobjects.
Most functions share global data Mostly the data is private and onlyfunctions inside the object canaccess the data.
Follows a top down approach inproblem solving
Follows a bottom up approach.
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 6/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 6
Need of OOP (Contd«)
World is made up of objects!
Orders
Manufactures
Ship via
ClientManufacturer
Product
Airplane
Truck
Purchasing a product
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 7/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 7
Need of OOP (Contd«)
Object Oriented Programming is an easy way of transforming real world problem into software
Fundamental knowledge of object oriented concepts isnecessary to adopt Object Oriented Programming paradigmfor software
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 8/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 8
Object Oriented Concepts
Abstraction
Encapsulation
Inheritance
Polymorphism
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 9/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 9
Object
An object represents an entity, either physical or conceptual
Every entity in the world is an object
Object has:
State
Behaviour
Identity
Truck
Paragraph
Linked ListData Structure
Physical Entity
Conceptual Entity
Conceptual Entity (Programatic)
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 10/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 10
Object Characteristics - State
The state of an object is one of the possible conditions inwhich an object may exist
The state of an object changes by Behavior
Represented by specific values for attributes
A. B. Chowbe
Name
Employee No
Date of joining
Status
A. B. Chowbe
10000
04/01/2006
Teaching
Object Object State
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 11/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 11
Object Characteristics - Behavior
Behavior determines how an object responds to requestsfrom other objects
Behavior is represented by the set of messages it canrespond to. Messages are operations that the object canperform.
Registration Manager
Course Allotment
(confirmation)
A.B.Chowbe
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 12/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 12
Object Characteristics - Identity
Every object has an unique identity. Two objects may havesame state, but can not have same identity.
Even if states of two objects are same, their identitiesshould be different. (Employee No. may work as identity)
A.B.Chowbe
teaches OOPA.B.Chowbe
teaches OOP
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 13/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 13
Class
A Class is a description of a group of objects with commonproperties (attributes) & behavior (operations)
An object is an instance of a class
eg. A.B.Chowbe is an object of Teacher class
Example: Course Class
Properties Behavior
Name Add a student
Location Delete a student
Days offered Get course roster
Credit hours Determine if it is fullStart time
End time
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 14/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 14
Class & Object
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
Contains attributes & operations
Objects are grouped into classes
P.A.Walter G.A.Khanna A.B.Chowbe
Teacher
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 15/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 15
Class Elements
Attributes
CourseOffering
number startTime
endTime
..
:CourseOffering
Number=CS201
endTime=1230startTime=1030
..
:CourseOffering
Number=CS202
endTime=1500startTime=1300
Class
Object
Object
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 16/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 16
Class Elements (Contd«)
Operations
CourseOffering
number
Add StudentDelete StudentGet Start TimeGet End Time
startTimeendTime
..
:CourseOffering
Number=CS201
endTime=1230startTime=1030
..
:CourseOffering
Number=CS202
endTime=1500startTime=1300
Class
Object
Object
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 17/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1710/19/2010 CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited 17
Abstraction
Abstraction is the process of hiding the details and exposingonly the essential features of a particular concept or object
In abstraction, one captures only the essential attributes andbehaviors of a component
Example:
Telephone has a lot of attributes such as colour, shape,model make and behaviors such as receive call, make call.Internally, it is made up of circuits, chips and othercomponents. But to buy or use a Telephone, we don't needto know the internal workings of the phone.
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 18/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 18
Encapsulation
Encapsulation: Implementation details are hidden from theoutside world
Encapsulation is the way by which abstraction is achieved
Example:
The electronic circuit used in the telephone is hidden from theuser. This is Encapsulation.
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 19/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 19
What is an Interface?
An interface provides a collection of operations that are usedto specify a service of a class or a component
An interface is the fundamental means of communicationbetween objects
Each class design specifies the interfaces for the properinstantiation and operation of objects
Any behavior that the object provides must be invoked by a
message sent using one of the provided interfaces
Polygon
Draw
Move
Scale
Rotate
Interface
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 20/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 20
Message Passing among Objects
Data
Function
Data
Function
Data
Function
Data
Function
State (Data) is kept
accessible only to a
set of functions.
Behavior of theobject is exposed
using methods.
An object communicates
with another object by
passing messages
(invoking methods)
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 21/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 21
Relationship among Classes
Composition (Has-A Relationship)Defines a composite object type
Example:Object of Color is an attribute of Automobile class Automobile
Color shade
Color string name
int red;
int green
int blue
Has-A Relationship
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 22/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 22
Relationship among Classes
Inheritance (Is-A Relationship)
Hierarchy according to level of abstraction
When the classes have µis a kind of¶ relationship between them,this relationship is inheritance
Increasing
Generalization
Increasing
Specialization
Art
Music Films
Classical Rap
Commercial Documentary
Parent- Child
relationship(Is-A Relationship)
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 23/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 23
Types of Inheritance
Single inheritance
Classes have single parent class
Bank Account
balance
number
name
Withdraw()
CreateStatement()
Current Account
Withdraw()
Saving Account
GetInterest()
Withdraw()
Subclasses
Superclass
(parent)
Ancestor
Descendents
GeneralizationRelationship
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 24/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 24
Types of inheritance
Multiple inheritance
One class has more than one parent class
Flying Entity Animal
Airplane Helicopter Bird Wolf Horse
multiple
inheritance
Subclass/ChildClass/Derived
Class
SuperClass/Parent
Class/Base Class
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 25/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 25
What is inherited?
A subclass inherits its parent¶s attributes, operations
A subclass may:
Add additional attributes, operations
Redefine inherited operations (i.e. overriding)
Common attributes & operations are shown at the highestapplicable level in the hierarchy
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 26/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 26
Polymorphism
The ability of one thing to appear in many forms dependingon context
Volume Control
Channel Control
Surrounding control
Sound Equaliser control
Common Interface
Videocon TV Samsung TV SansuiVideo
Remote
Volume Control
Volume
Control
Volume Control
Same functionality is implemented in
different devices in different manner.
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 27/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 27
Polymorphism
The ability of the objects to respond to the same message indifferent ways is also called as polymorphism
1. Give me a ring
3. Give me a ring
2. Dial a phone no.
4. Gives an engagement ring
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 28/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 28
Overloading & Overriding
Two ways of achieving Polymorphism
Overloading
The ability of the objects to respond to the same message indifferent ways is achieved using overloading
Overriding
The ability to respond differently than the parent, is achived usingoverriding
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 29/30
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 29
Summary
In this session, we have covered:
Object
Class
Abstraction
Encapsulation
Message Passing
Inheritance
Polymorphism
8/8/2019 ITP OO Concepts
http://slidepdf.com/reader/full/itp-oo-concepts 30/30
Tech Mahindra Limited confidential© Tech Mahindra Limited 2007
Thank You