Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Lecture 6 Introduction to Object Oriented Programming

Uploaded by

Fatima Chaudhry
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lecture 6 Introduction to Object Oriented Programming

Uploaded by

Fatima Chaudhry
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Application Development

Lecture 6
Introduction to Object Oriented Programming
Outline
• Towards Structured Programming
• Procedural Languages
• Problem With Procedural Languages
• Object Oriented Programming
• Example of Real-World Objects
• Characteristics of Object-Oriented Programming
• Objects & Classes
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Towards Structured Programming
• Early Versions of Pascal , Fortran , BASIC and COBOL
• Used GOTO statements which made the program un-structured
• Later versions included control structures like Loops - Structured Programming
• Procedural Languages ( C , Later Versions of Pascal , Fortran , Basic)
• Structuring the program by decomposing tasks into methods
• Dividing program in to modules / functions
• Programs broken into smaller units = Functions
• Each Function with a clearly defined purpose and interface to other Functions in the
program
• Programs become larger  difficulty in comprehending

3
Towards Structured Programming
• Problems with Procedural Languages
• Functions had unrestricted access to global data
• Large programs have many functions, many global data items and many connections
between functions and data
• Difficulty in conceptualization
• Difficult to modify

4
Towards Structured Programming

• Problems with Procedural Languages


• Poor Model of Real World
• In real world data and functions are not separated.
• In real world – Objects – Both Attributes and Behavior
• Attributes – Characteristics – Data in the program
• Behavior – Action taken in response to some stimulus – Function in the Program

5
Towards Structured Programming

• All Computer Programs Consists of two elements


• Code and Data
• Conceptually , a program can be organized around:
• Its code , or its data
• Programs can be written around :
• What is happening , or who is being affected
• The First Approach – Procedural Programming
• Program built around its code
• Focus on what is happening
• A process-oriented model
• The process-oriented model can be thought as code acting on data
• Procedural Languages like C employ this model
• Large Programs  Increasing Complexity  Hampered Structure
Object Oriented Programming
• The Second Approach –
• Program organized around
• Its data ( Objects)
• A set of well-defined interfaces to its data (Functions)
• Data is the controlling entity – not the code
• This second approach is called object-oriented programming
• Task are solved by collaborating different objects
• Each object has its own set of data, together with a set of methods that act upon the
data
Object Oriented Approach

Data Object 1
Member
Functions

Data
Data
Member
Object 2 Member Functions
Object 3
Functions

8
Objects - Real World Example

9
Objects in the Real World
Objects – Real World Examples

Command Button
Real World Objects

Traffic Light
Object Oriented Approach
• Objects
• Combine both DATA and FUNCTIONS into a single unit – OBJECT
• Member Data
• Each Object has its own copy of member data
• Member Function
• – object’s function – provide the ONLY way to access member data of the object
• Can not access data directly – Data is hidden – safe from accidental
alterations
• Different objects interact with each other by calling one another’s member
functions

13
Objects Interaction
Characteristics of Object Oriented
Language
• Objects
• While solving a problem, instead of asking “how to divide problem in
functions?” we ask, “how the problem will be divided into objects?”
• Helps in easier design of the solution
• Examples of Real-World Objects

15
Characteristics of Object Oriented
Language
• Classes
• A class is a blueprint ( template) for a set of objects
• It is an abstract description of similar objects
• Specifies what DATA and what FUNCTIONS will be included in the objects of the class
• A class basically defines similar objects in terms of state and behavior

16
Characteristics of Object Oriented
Language
• Class
• A BankAccount Class
Characteristics of Object Oriented
Language
• Abstraction
• Abstraction is one of the key concepts of OOP
• Its main goal is to handle complexity by hiding the un-necessary implementation details
• Abstraction Example
• When send Text Message you just type and send – do not care about how its actually transmitted
• When You drive a car , you only care about top level details like gears, steering, speed , brakes etc
• You don’t need to care about how the engine, transmission and braking system works
• When you use a coffee machine to make coffee
• You just need to provide water , coffee beans and select the type of coffee
• You don’t need to care about how the coffee machine works
• Someone else worried about that and created a coffee machine which provides abstraction to low level details
• Abstraction is achieved through hierarchical Classifications
• This allows you to breakdown a complex system into smaller manageable pieces
• From the outside car is a single object
• But , internally it consists of subsystems like Steering , Brakes , Sound System , Fuelling Systems etc
• Abstraction is achieved through Abstract Classes and Abstract Methods
Characteristics of Object-Oriented
Languages
• Encapsulation
• Encapsulation means binding data and functions that manipulate that data into one
unit called a class
• The purpose is to keep safe – both data and functions from outside world
• It is also called Information Hiding

19
Characteristics of Object Oriented
Languages
• Inheritance
• It is a mechanism of deriving a new class from an old class that is pre-defined
• The old class is called the base or super class
• The new class is called the derived class
• Subclass shares common characteristics with the class from which it is derived.
• Each subclass also has its own particular characteristics.
• For Example
• Animals  Herbivores  Giraffe
• Animal  Herbivores Mammals  Cow
• Animals  Omnivores  Mammals  Bear

20
Inheritance –Example I
Inheritance – Example II
Inheritance – Example III

Generalization

Specialization
Characteristics of Object Oriented
Languages

• Reusability
• Once a class properly written, it can be distributed for others to use
• Also, the Inheritance provides the extension to reusability – take existing class
and without modification add new features to it

24
Characteristics of Object Oriented
Languages
• New Data Types
• Objects help in creating new Data Types
• Example – A point in co – ordinate System
• Time
• Date
• Distance

25
Characteristics of Object-Oriented
Languages
• Polymorphism
• Using Operators or Functions in different ways depending on what they are operating
on is called polymorphism
• We can use the same methods for different implementations based on the arguments

26

You might also like