Functional vs Object Oriented Programming-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

This lecture was delivered by Dr. Jameel Ahmad at Quaid-i-Azam University for Object Oriented Programming course. It includes: Object, Oriented Programming, Introduction, Model, Syntax, Functional, Procedural, Class, Instance

Typology: Slides

2011/2012

Uploaded on 07/13/2012

saqqi
saqqi 🇵🇰

4

(33)

40 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ObjectOrientedProgramming
CourseInstructor:Mr.ShahzadRafiq
Assist.ProfessorComputerScience,
FacultyofComputing,MohammadAliJinnahUniversity,
Islamabad.
Office:113,1st floor,BlockA.Email:[email protected]
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Functional vs Object Oriented Programming-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

1

Object^ Oriented

Programming

Course^ Instructor:

Mr.^ Shahzad

Rafiq

Assist.^ Professor^ Computer

Science, Faculty^ of^ Computing,

Mohammad^ Ali^ JinnahUniversity,^ Islamabad. st^ Office: 113, 1 floor, Block^ A.^ Email:^ [email protected]

2

This^ Week

•^ Introduction •^ Object^ Orientation:

Introduction

to^ Object

Model • Syntax^ comparison

of^ ;

-^ Functional^

vs^ OO^ Programming

4

Example^

Procedural

Programming

Struct^ BankAccount { double^ balance;int^ accNo;} void^ deposit(BankAccount

acc , amount) {^ acc .balance + = amonut;}^ void^ withdraw^ (BankAccount

acc , amount) {^ acc .balance -^ = amonut;} double getBalance(^ BankAccount

acc ) { cout<<^ acc .aacNo<<

acc .balance; } void^ transferMoney(BankAccount

acc1, BankAccount^ acc2 ) { acc2.balance + = amount;acc1.balance - = amount; }

void^ main^ (void){^ BankAccount^ aliAccount = new

BankAccount ; BankAccount^ assadAccount = new

BankAccount ; //Operations^ on^ ali^ account; deposit( aliAccount ,10000);deposit( aliAccount ,5000);getBalance( aliAccount

); withdraw( aliAccount , 1000) ;getBalance( aliAccount

); //Operations^ on^ assad^ account deposit( assadAccount ,1000);deposit( assadAccount ,5000);getBalance( assadAccount

); withdraw( assadAccount

, 1000); getBalance( assadAccount

); }

5

Example^ Object

Oriented^

Programming

Class^ BankAccount {^ private:double^ balance;int^ accNo;^ public :void^ deposit( double

amount){ balance+= amonut;} void withdraw (double amount){ balance - = amonut;} void getBalance() { cout<<accNo<<balance;} }

void^ main^ void(){ BankAccount^ aliAccount = new

BankAccount() ; BankAccount^ assadAccount = new

BankAccount() ; //Operations^ on^ ali^ account;^ aliAccount.^ deposit( 10000);^ aliAccount.^ deposit( 5000);^ aliAccount.^ getBalance();^ aliAccount.^ withdraw( 1000);^ aliAccount.^ getBalance(); //Operations^ on^ assad^ account;^ assadAccount.^ deposit( 1000);^ assadAccount.^ deposit( 5000);^ assadAccount.^ getBalance();^ assadAccount.^ withdraw( 1000);^ assadAccount.^ getBalance(); }

7

Object

•^ An^ object

contains^ both

data and^ methods

that^ manipulate

that^ data

-^ The^ data^ represent

the^ state of^

the^ object

-^ Data^ can^ also

describe^ the

relationships

between

this^ object^ and

other^ objects

•^ Example:

A^ BankAccount

might^ have

-^ A^ balance

(the^ internal

state^ of^ the^ account)

-^ An^ account number

(some^ object

representing

an^ identity)

8

Why^ Object

‐Oriented?

- Is^ OO^ A^ New

Paradigm? Programming^ Paradigms

Imperative^

Procedures^ &^ Algorithms Function‐oriented

Mathematical

functions Logic‐oriented^

Goals,^ predicate

logic Object‐oriented

Classes^ &

Objects Rule‐oriented^

Expert^ systems Constraint‐oriented

Invariant^ relations

-^ Paradigm:

“way^ of^ looking

at^ things”

-^ Yes!^ OO^ does

present^ a^ new

way.

10

All^ about^

to^ implement

“Object^ Model”

-^ Consisting^ of

objects^ and classes. Describes^ what^ will be necessary^ to^ make^ the desired software^ product.

-^ The^ object^ model

is^ the result^ of^ OOA^ and

OOD^ and the^ basis^ for implementation. • There^ exists^ no

standard object^ model • The^ following^ aspects should^ in^ any^ case

be contained^ in^ a^

good^ object model:

TypingAbstractionEncapsulationModularityHierarchyConcurrencyPersistence

11

-^ Typing :^ –^ “It^ is^ the

enforcement^

of^ the^ class^ of

an^ object,

such^ that^ objects

of^ different^ types

may^ not^ be

interchanged,

or^ at^ the^ most,

they^ may^ be

interchanged^

only^ in^ a^ very^

restricted^ ways

-^ Abstraction:^ –^ An^ abstraction

denotes^ the^ essential

characteristics

of^ an^ object^ that

distinguish^ it^

from

all^ other^ kinds

of^ objects^ and

thus^ provide^

crisply

defined^ conceptual

boundaries,^ relative

to^ the

perspective^ of

the^ view”.

-^ Encapsulation:^ –^ “It^ is^ the

process^ of^ compartmentalizing

the

elements^ of^ an

abstraction^ that

constitute^ its

structure^ and^

behavior,^ it^ serves

to^ separate^ the

contractual^ interface

of^ an^ abstraction

and^ its

Object^ implementation” Model^ (Continue…)

13

Abstract

Data^ Type

(ADT)

•^ An^ Abstract

Data^ Type (ADT)

bundles^ together:

-^ some^ data,

representing

an^ object^ or

"thing"

-^ the^ operations

on^ that^ data

•^ The^ operations

defined^ by

the^ ADT^ are

the

only^ operations

permitted^

on^ its^ data

•^ Example:

a^ BankAccount

,^ with^ operations

deposit,^ withdraw, getBalance

,^ etc.