0% found this document useful (0 votes)
15 views

OOP

Uploaded by

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

OOP

Uploaded by

Ratna Rajya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Unit-5

Object oriented programming (OOP)

Programming Paradigm

Programming paradigm is a way to classifies programming language according to their style of


programming and features they provide.

Some most popular programming paradigms are as follows

 Imperative programming
 Declarative programming
 Structured programming
 Procedural programming
 Object Oriented programming
 Functional programming

 Imperative Programming

Imperative programming is the oldest paradigm and is still in practice. It performs step by step
task by changing state through assignment statement. It focuses on what to do and how to do.
Imperative programming lacks the support of modularity. Example: imperative programming languages
are FORTRAN, COBAL, BASIC, JAVA, C programming etc

 Declarative Programming

Declarative programming focuses on the logic of software without actually describing the
control flow. Imperative programming defines each steps to get the result whereas declarative
programming defines the logic of computation. Example of declarative programming is PPOLOG
(Programming logic)

Example: in JavaScript
constsum = a =>b =>a + b;
console.log (sum (5) (3)); // 8

 Structural Programming

Structural programming is the kind of imperative programming, focuses of modular


programming. Structural programming makes extensive use of loop, function, and block. Example of
structural programming is C language.

 Procedural Programming

Procedural Programming is derived from structural programming. It inherits all properties of


structural and imperative programming. Procedural programming is based on procedural call. It has
“GOTO” or “JUMP” statements or procedural call. Example of procedural programming is PASCAL.

 Object-Oriented Programming

Object oriented programming is widely practice programming paradigm. It is based on the


concept of class, object. It utilizes several techniques including modularity, polymorphism, inheritance,
and encapsulation. Example of object oriented programming is C++, java, ASP.Net
 Functional Programming

Functional programming uses a combination of function call to drive a flow of program. It is


completing different programming approach from all above paradigm. Example of functional
programming language is Python.

Object Oriented Programming


Object-oriented programming (OOP) is a programming language model that organizes software design
around data or objects, rather than functions and logic. An object can be defined as a data field that has
unique attributes and behavior.

Features of OOP are:

 Emphasis is given data rather than procedures.

 Programs are divided into objects and modules.

 Functions and data are bind together.

 OOP is based on data hiding principle.

 New data and functions can be easily added whenever necessary.

 Bottom-up method is used in programs.

Advantages of OOP are:

I. Eliminate redundancy.

II. Allows building secure program.

III. Ease in division of job.

IV. Reduce complexity.

V. Provide extensibility.

VI. Saves development time and increase productivity.

VII. Allows designing simpler interfaces.

Disadvantages of OOP are:

I. Size- Object oriented programs are much larger than other programs.

II. Slow Speed – Due to large size of the programs its execution speed becomes slow.

III. Many skills – A programmer required many skills for a better programming. Different skills like
programming skills, designing skills, logical thinking and problem-solving skills are needed..

IV. Complex Design – Designing and proper implementation of Object Oriented Programming
(OOP) concepts is complex and burdensome.

Application areas of OOP are:

I. User interface design such as windows, menu.

II. Real Time Systems


III. Simulation and Modeling

IV. Object oriented databases

V. AI and Expert System

VI. Neural Networks and parallel programming

VII. Decision support and office automation systems etc.

Different between OOP and POP

OOP POP

It is the most recent programming concept which uses the It is the old programming concept that uses the top-
bottom-up approach. down approach.

Programs are divided into a number of entities called object. Programs are divided into a number of functions.

Emphasis is on data rather than on procedures. Emphasis is on procedures rather than on data.

It does not allow data to move freely around the program It allows data to move freely around the program
from one object to another object. from one function to another function.

Data is hidden inside the object and cannot be accessed by Data is open and can be freely accessed by all the
external functions. programs.

Problem is viewed as a real world entity. Problem is not viewed as a real world entity

OOP is written by using HLL such as C++, Java, ASP.Net etc. POP is written by using HLL/MLL such as C,
FORTRAN etc.
The principles of OOPs are:
 Class- Class is a blueprint for an object. A class is the user defined data type with a template that
serves to define its properties. A class can have any number of properties and methods to access
the value of various kinds of methods. A class is a collection or group of similar objects that have
same properties, common behavior and relationships. Each class describes a set of individual
objects.

The general form of declaring a class is


Class class_name
{
Access_specifier:
Member_data_1;
Member_data_2;
………………………..
Access_specifier:
Member_function_1;
Member_function_2;
………………………………
};

 Object-

- An object is any entity, things or organization that exits in real world. It consists of two
fundamental characteristics: its attributes and behaviors.

- Objects are the basic run time entities in an object oriented system.
- They represent any item that the program can handle.
- When a program is executed, the objects interact by sending messages to one another.
- Eg: Consider an object ‘Student’ with data (name, roll, mark) and function total(), average(),
display().
 Encapsulation- The Encapsulation is the mechanism of combining data function together into a
single unit.
- It prevents the data being accessed by other code.

There are three type of encapsulation modifier: they are:


1. Public: Public data and functions are accessible from outside the class in limited amount.
2. Protected: Protected data and functions are accessible from outside the class in limited amount.
3. Private: Private data and functions can only be accessed from within the class.

 Abstraction- Abstraction is the act of representing the essential features without including the
background details or explanations.
- Classes are the concept of abstraction. So, class is an abstract data type.
- It can manage the program complexity.
Advantages of Data Abstraction:

 Helps the user to avoid writing the low level code


 Avoids code duplication and increases reusability.
 Can change internal implementation of class independently without affecting the user.
 Helps to increase security of an application or program as only important details are provided to
the user.

 Inheritance- Inheritance is the capability of one class to acquire properties and characteristics from
another class. The class whose properties are inherited by other class is called the parent or base or
super class. And, the class which inherits properties of other class is called Child or Derived or Sub
Class.

Purpose of inheritance

1. Code reusability
2. Method overriding
3. Use of virtual function

Advantages of Inheritance

1. Reusability
2. Saves time and effort
3. Extendibility of the code

Aminal
Class Dog inherits properties from
its super class Animal
Dog

Types of inheritance

1. Single Inheritance

When a single class is being inherited by a class, it is called single or simple inheritance. In other word, a
derived class with only one base class is called single inheritance.

B
2. Multi Level inheritance

Multilevel inheritance is a process of deriving a class from another derived class.


Fig: MultilevelClass A
B
C
Inheritance
Class A

Class B

Class C

Fig: Multilevel Inheritance


3. Hierarchical Inheritance

Hierarchical Inheritance is the process of deriving two or more classes from single base class.

Class A

Class B Class C Class D

4. Multiple Inheritance

Multiple inheritances are a type of inheritance in which new class is created from more than one
base class.
A B

 Polymorphism- Polymorphism means “having many forms”. The polymorphism allows different
object to respond to the same message in different ways, the response specific to the type of
object. It is important when object oriented programs dynamically creating and destroying the
objects in runtime. Example of Polymorphism in oop:

1)operator overloading
2)function overloading etc.
There are two types of polymorphism:
1)Runtime polymorphism
2)Compile time polymorphism
Example:
Different between OOP and POP

OOP POP

It is the most recent programming concept which uses the It is the old programming concept that uses the top-
bottom-up approach. down approach.

Programs are divided into a number of entities called object. Programs are divided into a number of functions.

Emphasis is on data rather than on procedures. Emphasis is on procedures rather than on data.

It does not allow data to move freely around the program It allows data to move freely around the program
from one object to another object. from one function to another function.

Data is hidden inside the object and cannot be accessed by Data is open and can be freely accessed by all the
external functions. programs.

Problem is viewed as a real world entity. Problem is not viewed as a real world entity

OOP is written by using HLL such as C++, Java, ASP.Net etc. POP is written by using HLL/MLL such as C,
FORTRAN etc.

Multiple Choice Questions

1. OOP stands for….

a. Operator overloading programming b. Object Oriented Programming

c. Object overloading programming d. None of the above

2. ……… is a concept or thing with defined boundaries that are relevant to the problem we are dealing
with

a. object b. Class c. Variable d. None of the above

3. ……. is a collection or group of similar objects that have the same properties, common behavior and
relationships.
a. Object b. Class c. Constant d. None of the above

4. ………. is a property that allows the reuse of an existing class to build a new class.

a. class b. Operation c. Constant d. Object

5. …. is the process that allows selective hiding of data and functions in a class.

a. class b. inheritance c. encapsulation d. Polymorphism

6. …… enables the same function to behave differently on different classes.

a. class b. Data abstraction c. encapsulation d. Polymorphism

7. …. Is the process of identifying properties and methods related to a particular entity as relevant to the
application?

a. Polymorphism b. Data abstraction c. encapsulation d. None of the above

8. Under …. Inheritance, there is a derived class with only one base class.

a. Single b. Multiple c. Hierarchical d. None of the above

9. In …….. Paradigm, programs are written as a collection of classes and objects.

a. procedural paradigm b. Structural paradigm c. Object Oriented paradigm d. None of the above

10. …… is a programming paradigm based upon the concept of procedure calls, in which statements are
structured into procedures?

a. procedural paradigm b. Structural paradigm

c. Object Oriented paradigm c . None of the above.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy