Академический Документы
Профессиональный Документы
Культура Документы
INTRODUCTION
TO
OBJECT ORIENTED
PROGRAMMING SYSTEM(OOPS)
Objectives:
PROCEDURAL PROGRAMMING
As the name suggests, focus is on Procedures.
Programs written in Procedural programming
Structured programming
MAIN PROGRAM
FUNCTIO
FUNCTION
N1
FUNCTION
FUNCTION
GLOBAL DATA
FUNCTION
PROCEDURAL PROGRAMMING
As seen from figure:
Functions are interdependent
They share global data
Hence:
Procedures/functions are often hard to reuse.
programs are often hard to extend and maintain.
More maintenance cost.
Less data security.
automobiles)
OOP
Object 2
Object 1
Data
Data
Function
Function
Object 3
Data
Function
Advantages of OOP
Difference Between
Procedure Oriented Programming (POP)
&
Object Oriented Programming (OOP)
Basic terminology
14
object
- usually a person, place or thing (a noun)
method
- an action performed by an object (a verb)
attribute
- description of objects in a class
class
- a category of similar objects (such as automobiles)
- does not hold any values of the objects attributes
What Is an Object?
Informally, an object represents an entity, either
Physical entity
Truck
Conceptual entity
Chemical
Process
Software entity
Linked List
Attributes
is represented by
attributes
and
relationships.
Behavior is represented by
operations, methods, and
state machines.
Object
Operations
Professor Clark
Name: J Clark
Employee ID: 567138
Date Hired: July 25, 1991
Status: Tenured
Discipline: Finance
Maximum Course Load: 16 classes
Name: J Clark
Employee ID: 567138
HireDate: 07/25/1991
Status: Tenured
Discipline: Finance
MaxLoad: 3
Professor Clark
Su
bm
Professor Clark
itF
in
al
G
ra
de
s(
Professor Clark
Se
tM
ax
Lo
ad
()
A
() cce
pt
Co
u
rs
eO
ffe
rin
g
Professor J Clark
teaches Biology
Professor J Clark
teaches Biology
What Is a Class?
A class is a description of a set of objects that share the same
Objects
Attributes
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
Professor Smith
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
Professor Mellon
Professor Jones
Professor
Operations
What Is an Attribute?
An attribute is a named property of a class that describes a
- name
- address
- studentID
- dateOfBirth
Student
name: M. Modano
address: 123 Main
studentID: 9
dateofBirth:
03/10/1967
Objects
- name
- address
- studentID
- dateOfBirth
name: D. Hatcher
address: 456 Oak
studentID: 2
dateofBirth: 12/11/1969
What Is an Operation?
An operation is the implementation of a service that can
Operations
+ get tuition()
+ add schedule()
+ get schedule()
+ delete schedule()
+ has pre-requisites()
Professor
- name : String
- age : int
- speciality : String
+getName() : String
+getAge() : int
+getSpeciality() : String
name = wang
age = 35
speciality = computer
Polymorphism
Inheritance
Encapsulation
Abstraction
Object Orientation
Abstraction
"To represent the essential feature without representing the
background details."
lets you focus on what the object does instead of how it does it.
provides you a generalized view of your classes or object by
providing relevant information.
process of hiding the working style of an object, and showing
the information of an object in an understandable manner.
Analogy:
When you drive a car, you dont have to know how the
gasoline and air are mixed and ignited.
Instead you only have to know how to use the controls.
Example
Real World Example of Abstraction
Suppose you have an object Mobile Phone.
Suppose you have 3 mobile phones as follows:
Nokia 1400 (Features:- Calling, SMS)
Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera)
Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading
E-mails)
Abstract information (Necessary and Common Information)
Encapsulation
Wrapping up data member and method together into a
Polymorphism
Polymorphismthe same word or phrase can be mean
Example: Polymorphism
Get Current Value
get
Cu
rre
Stock
ntV
a lu
e()
get
Cu
rre
Bond
ntV
a lu
e()
get
Cu
rre
ntV
a lu
e()
Mutual Fund
In this example, a requesting object would like to know the current value of a financial instrument. However,
the current value for each financial instrument is calculated in a different fashion. The stock needs to
determine the current asking price in the financial market that it is listed under. The bond needs to determine
the time to maturity and interest rates. A mutual fund needs to look up the closing price from the day from
the fund management company.
In a non object-oriented development environment, we would write code that may look something like this:
IF financialInstrument = Stock THEN
calcStockValue()
IF financialInstrument = Bond THEN
calcBondValue()
IF financialInstrument = MutualFund THEN
calcMutualFundValue()
With object technology, each financial instrument can be represented by a class, and each class would know
how to calculate its own value. The requesting object simply needs to ask the specific object (for example,
Stock) to get its current value. The requesting object does not need to keep track of three different operation
signatures. It only needs to know one.
Polymorphism allows the same message to be handled in different ways depending on the object that
receives it.
Inheritance
Is the process by which new class is created from existing
class.
Derived classes have all the features of the base class in
addition to some new features.
The new inheriting class is called derived or sub class and
inherited class is called base or super class.
Term inheritance comes from inheritance of traits like eye
color, hair color, and so on.
Is an is a kind of relationship.
An Inheritance Hierarchy
Vehicle
Automobile
Sedan
Motorcycle
Sports Car
Bus
School Bus
Luxury Bus