0% found this document useful (0 votes)
14 views22 pages

Chapter 1 Introduction To Object Oriented Programming

Uploaded by

naboniniguse49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views22 pages

Chapter 1 Introduction To Object Oriented Programming

Uploaded by

naboniniguse49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter One

Introduction to
Object oriented
Programming

1
Introduction to Programming
languages
• Programming languages are set of rules, symbols and special words
used to construct a computer program. There are 3 levels of PLs.
1. Low level programming languages
• It uses machine languages
• Only 0s and 1s are used to develop a program
• They are very fast because there is no intermediate device between them
• It is only machine (compiler) understandable language
2. Assembly programming language
• Uses mnemonics(short English words) eg: add, sub, mov
• Difficult to write and debug the errors
• Requires assembler to translate into machine code

2
Introduction to Programming languages
cont…
3. High level programming language
• Easy to develop programs
• Easy to debug errors
• Requires translator to convert into machine code
• Eg. Java. C++, PHP, C# etc…

3
Programming paradigm
• Programming paradigm are the patterns or models of programming
every programming languages design to fit into a specific paradigm.
There are 2 paradigms
• Procedural (structural) oriented programming (POP):
• The objects oriented programming(OOP):

4
Procedural (structural) Oriented
programming paradigm (POP):
• In the POP, one focus is on the decomposition of problems into various
functional components.
• The program is organized into a collection of functions (also known as
procedure or subroutines) which will be executed in a defined order to
produce the desired result.
• Most of the programs developed in the olden days were procedural.
• In this paradigm more emphasis is given to the function (procedure) ,which
was involved in the problem solving
• It does not model real world problems very well.
• This is because function are action oriented and do not really correspond to
the elements of the problems
• eg: COBOL, FORTRAN, and C, B. 5
POP MAIN PROGRAM GLOBAL DATA

FUNCTION 1 FUNCTION 2 FUNCTION 3

FUNCTION 4 FUNCTION 5

6
An Example Of The Procedural Approach
(Presentation Software)
• Break down the program by what it does (described with actions/verbs)
PowerPoint

Filing Editing … Helping

Creating Opening a Saving a … Exiting


new document document program
document
The objects oriented paradigm:
• This program is a relatively new approach to problem solving in
objects oriented paradigm.
• The main issue is modeling real life objects which take part in
computerized system that is being build.
• OOP treats data as a critical element in the program development and
does not allow it to flow freely around the system.
• OOP allows decomposition of a program into a number of entities
called objects and then builds data and function around these
objects.
• Eg. C++, JAVA, C#, PHP etc.
8
An Example Of The Object-
Oriented Approach
(Simulation)
• Break down the program into entities (classes/objects - described
with nouns)
Zoo
Animals Buildings ETC.

Visitors
Lions

Staff
Tigers
Admin
Bears (oh
my!) Animal
care
Classes/Objects
• Each class of object includes descriptive data.
• Example (animals):
• Species
• Color
• Length/height
• Weight
• Etc.
• Also each class of object has an associated set of actions
• Example (animals):
• Sleeping
• Eating
• Excreting
• Etc.
OOP
Object 2
Object 1

Data Data

Function Function

Object 3

Data

Function

11
The structure, or building blocks, of object-oriented programming include the following:
• Objects are instances of a class created with specifically defined data.
• Objects can correspond to real-world objects or an abstract entity.
• Methods are functions that are defined inside a class that describe the behaviors of
an object.
• Each method contained in class definitions starts with a reference to an instance
object.
• Additionally, the subroutines contained in an object are called instance methods.
• Attributes are defined in the class template and represent the state of an object.
Objects will have data stored in the attributes field. 12
POP Vs OOP
POP
Main program is divided into small parts depending on the
functions.
The Different part of the program connects with each other
by parameter passing & using operating system.
Every function contains different data.
Functions get more importance than data in program.
Most of the functions use global data.

13
POP Cont.…
Same data may be transfer from one function to another
There is no perfect way for data hiding
More data or functions may not be added with program if necessary
with out changing of the whole program.
To add new data in program, user should be ensure that function
allows it.
Top down process is followed for program design (breaking down of a
system to gain insight into its compositional sub-systems)

14
OOP
Main program is divided into small object depending on the problem.
Functions of object linked with object using message passing.
Data & functions of each individual object act like a single unit
Data gets more importance than functions in program.
Each object controls its own data.

15
OOP cont..
Data hiding possible in OOP which prevent illegal access of function
from outside of it.
More data or functions can be added with program if necessary. For
this purpose full program need not to be change.
Message passing ensures the permission of accessing member of an
object from other object.
Bottom up process is followed for program design(piecing together of
systems to give rise to more complex systems).

16
Features of Object oriented
Programming
• The Objects Oriented programming language supports all the features
of normal programming languages.
• In addition it supports some important concepts and terminology
which has made it popular among programming methodology.
• The important features of Object Oriented programming are:
Inheritance
Polymorphism/ Overloading
Data Hiding /Encapsulation

17
Inheritance
• Inheritance as the name suggests is the concept of inheriting or deriving
properties of an exiting class to get new class or classes.
• In other words we may have common features or characteristics that may be
needed by number of classes.
• So those features can be placed in a common tree class called base class
• And the other classes which have these characteristics can take the tree class
and define only the new things that they have on their own in their classes.
• These classes are called derived class.
• It helps in reducing the code size
• Since the common characteristic is placed separately called as base class and it
is just referred in the derived class.
18
Polymorphism
• Poly refers many
• Similar objects can respond to the same message in different ways.
• For example, you might have a system with many shapes.
• However, a circle, a square, and a star are each drawn differently.
• Using polymorphism, you can send each of these shapes the same message
(for example, Draw), and each shape is responsible for drawing itself.
• Overloading means two or more methods having the same method name
but takes different input parameters.
• This called static because, which method to be invoked will be decided at
the time of compilation
19
Data Encapsulation/ Data Hiding
The data is hidden inside the class by declaring it as private inside the
class.
When data or functions are defined as private it can be accessed only by
the class in which it is defined.
When data or functions are defined as public then it can be accessed
anywhere outside the class.
Object Oriented programming gives importance to protecting data which
in any system.
This is done by declaring data as private and making it accessible only to
the class in which it is defined.
This concept is called data hiding. 20
Encapsulation cont.…
Data encapsulation, sometimes referred to as data hiding, is the
mechanism whereby the implementation details of a class are kept
hidden from the user.
The user can only perform a restricted set of operations on the hidden
members of the class by executing special functions commonly called
methods.
The actions performed by the methods are determined by the
designer of the class, who must be careful not to make the methods
either overly flexible or too restrictive.

21
Benefits of Object Oriented
Programming
1. Modularity:
• Modularity refers to the concept of making multiple modules first and then linking and combining
them to form a complete system. Modularity enables re-usability and minimizes duplication.

2. Information-hiding:
• By interacting only with an object's methods, the details of its internal implementation remain
hidden from the outside world.
3. Code re-use:
• If a class already exists, you can use objects from that class in your program.
4. Easy Debugging:
• If a particular object turns out to be a problem, you can simply remove it from your application and
plug in a different object as its replacement.
• This is analogous to fixing mechanical problems in the real world. 22

You might also like