oop’s

23
OOP OOP Object Oriented Programming Object Oriented Programming By : Tauseef Ahmad (107)

Upload: tauseef-ahmad

Post on 26-May-2015

630 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Oop’s

OOPOOPObject Oriented ProgrammingObject Oriented Programming

By : Tauseef Ahmad (107)

Page 2: Oop’s

Evolution of OOPEvolution of OOP

1,0

Machine LanguageAssembly LanguageProcedure-Oriented

Object-Oriented Programming

Page 3: Oop’s

Procedure-OrientedProcedure-Oriented

• The primary focus is on functions.

• It basically consist of list of instructions for computer to follow, and to organize these instructions into groups known as functions.

Page 4: Oop’s

Structure of POPStructure of POP[Procedure oriented programming][Procedure oriented programming]

Main Program

Function-1 Function-2 Function-3

Function-4 Function-5

Function-6 Function-7 Function-8

Page 5: Oop’s

Drawbacks of POPDrawbacks of POP• Most of the function share global data.

• It does not model real world problem very well.

Global data Global data

Function-1 Function-1 Function-1

Local Data Local Data Local Data

Page 6: Oop’s

Object-Oriented Object-Oriented LanguagesLanguages

• Object-oriented programming is not the right of any particular language.

• Like structured programming, OOP concept can be implemented using any language like C and Pascal.

Page 7: Oop’s

Object-Oriented Object-Oriented ParadigmParadigm

• Object-oriented programming (OOP) is a programming paradigm that uses "Objects" and their interactions to design applications and computer programs.

• Everything around us are objects interacting with each others.

• Each object has a set of features, including adjectives and verbs.

• Object-oriented paradigms is sometimes thought to be a simulation of the real-world around us, which make it the paradigm of choice for most application domains: GUIs, games, business, etc.

Page 8: Oop’s

Basic concepts of OOPBasic concepts of OOP• Objects• Classes• Data Abstraction and Encapsulation• Inheritance• Polymorphism• Dynamic Binding• Message Passing

Page 9: Oop’s

ObjectsObjects• Objects are the run-time entities.• It may represent a person, a place, a bank

account, a table of data or any item.• Objects take up space in the memory and have

an associated address like a structure in c.• Some examples : car, man, woman etc

Page 10: Oop’s

ClassesClasses• A class is an abstract definition of an object.

• Defines how would the object look like when created.

• Think of classes like the patents of actual inventions.

Page 11: Oop’s

EncapsulationEncapsulation• Wrapping up of data and functions into a single

unit is known as Encapsulation.• Encapsulation is hiding the functional details from

the object calling it.• Can you drive a car?

o Yes, I can!

• So, how does acceleration work?o Huh?

• Details encapsulated (hidden) from the driver.

Page 12: Oop’s

Data AbstractionData Abstraction• Abstraction refers to the act of representing

essential features without including the background details or explanation.

• An abstraction is a form of representation that includes only what is useful or interesting from a particular viewpoint.

• Example : A map is an abstract representation, since no map shows every detail of the territory it covers

Page 13: Oop’s

InheritanceInheritance• Inheritance is the process by which objects of one

class acquire the properties of objects of another class.

namephoneNumberaddresshourlyWage

WageContract()CalculateTax()PayTuition()DropCourse()

Professor

namephoneNumberaddresssalary

TeachCourse()CalculateTax()DevelopCourse()

OR

Employee

namephoneNumberaddress

CalculateTax()

SupportStaff Professor

TeachCourse()DevelopCourse()

salary

Subclasses

WageContract()

hourlyWage

SupportStaff

Page 14: Oop’s

InheritanceInheritance

Man

Suzuki

WomanBMW

Car Human

Page 15: Oop’s

PolymorphismPolymorphismint add(int a, int b, int c){

return (a+b+c); It will return addition} of 3 integer numbersint add(int a,int b){

return (a+b); It will return addition} of 2 integer numbersfloat add(float a, float b, float c){

return (a+b+c); It will return addition} of 3 float numbers

Page 16: Oop’s

PolymorphismPolymorphism• Polymorphism is a Greek term means the ability

to take more than one form.

Shape

Draw()

Circle Object

Draw (circle)

Box Object

Draw (box)

Triangle Object

Draw (triangle)

Page 17: Oop’s

Message PassingMessage Passing• The process by which an object:

o Sends data to another object.o Asks the other object to invoke a method.

• In other words, objects talk to each others via messages.

Page 18: Oop’s

18

Object and Their Object and Their InteractionInteraction

Program

Page 19: Oop’s

19

Object and Their Object and Their InteractionInteraction

Program

Tom, hold your sweep!

Page 20: Oop’s

20

Object and Their Object and Their InteractionInteraction

Program

Tom, hold your sweep!

Tom, beat jerry!

Page 21: Oop’s

21

Object and Their Object and Their InteractionInteraction

Program

Tom.holdYourSweep()

Tom.BeatJerry()

IN PROGRAMMING

Page 22: Oop’s

22

Object and Their Object and Their InteractionInteraction

Program

Tom.holdYourSweep()

Tom.BeatJerry()

IN PROGRAMMING

message

Page 23: Oop’s

23

Object and Their Object and Their InteractionInteraction

Program

Tom.holdYourSweep()

Tom.BeatJerry()

IN PROGRAMMING

message

message