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

1 Chapter Principal of Object Oriented Programming

OOP 1st chapter

Uploaded by

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

1 Chapter Principal of Object Oriented Programming

OOP 1st chapter

Uploaded by

basur00basur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

College of Business, Science &Technology (CBST), Mymensingh

Department of Computer Science and Engineering


Object Oriented Programming (OOP)

Chapter -1
Principles of Object Oriented Programming

Prepared by
Md. Masum Billah
Lecturer, Dept. of CSE, CBST
Mobile: 01793200796
Q. What is Programming?

Programming is the process of designing, writing, testing, and maintaining


computer programs to solve problems.
Programs can be used to automate tasks, process data, control hardware, build
websites and mobile applications, create video games, and perform many other
functions.

Q. Define Procedural oriented programming and write down the


characteristics of procedural oriented programming.

Procedural oriented programming (pop)


Procedural-oriented programming (POP) is a programming paradigm that
focuses on the procedures or functions that operate on data. In POP, a program
is divided into smaller procedures or functions that can be called to perform
specific tasks.
Example: c, basic, FORTRAN.

Characteristics of Procedural oriented programming


1. It focuses on procedures or functions that operate on data.
2. A program is divided into a number of functions and each function has
clearly defined purpose.
3. Most of the functions share global data.
4. Data moves openly around the system from function to function.
5. It follows top-down approach. Where the program starts with the main
function and then calls other functions as needed.

Prepared by Md. Masum Billah, Lecturer, Dept of CSE, CBST


Q. Describe how data are shared by functions in a procedure oriented
programs.

In procedure oriented program many important data items are placed as global
so that they can be accessed by all the functions. Each function may have its
own local data. Global data are more vulnerable to an unintended change by a
function.

Figure- Relationship of data and functions in procedure programming.

Q. Describe how data are shared by functions in an object oriented


programs.

Object oriented programming is an approach that provides a way of creating


object. Object is considered to be a module with data and set of operations that
can access that data. Since for each object memory is allocated separately.
Through function calling objects can share data among them.

Fig- Organization of data and function in OOP.

Prepared by Md. Masum Billah, Lecturer, Dept of CSE, CBST


Q. Define Object oriented programming. What the striking features are of
object oriented programming?

Object Oriented Programming


Object-Oriented Programming (OOP) is a programming paradigm that uses
objects to represent and manipulate data. In OOP, the program is divided into
objects that contain data and methods to manipulate that data.

Striking features of object oriented programming

1. Emphasis is on data rather than procedure.


2. Programs are divided into objects.
3. Data structures are designed such that they characterize the object.
4. Functions that operate on the data of an object are tied together in the data
structure.
5. Data is hidden & cannot be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added whenever necessary.
8. Follow bottom-up approach. This means starting with the smaller
building blocks of a system, such as classes and functions, and then
gradually building up to the larger system.

Q. Define the following terms-


Or, Describe the features of object oriented programming.
i) Object ii) Class iii) Inheritance
iv) Data abstraction and Data encapsulation v) Polymorphism
vi) Dynamic binding vii) Message passing

Object: In OOP object is the representation of real life entity. Objects are
instances of classes. Each object contains data and functions to manipulate the
data. Following statements declare two objects of class Box −
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box

Both of the objects Box1 and Box2 will have their own copy of data members.

Class: Class is the blue print for creating object. Objects are variables of the
type class. Once a class has been defined, we can create any number of objects
belonging to that class. A class definition starts with the keyword class followed
by the class name; and the class body, enclosed by a pair of curly braces. A

Prepared by Md. Masum Billah, Lecturer, Dept of CSE, CBST


class definition must be followed either by a semicolon or a list of declarations.
For example, we defined the Box data type using the keyword class as follows –

class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};

Inheritance: It is the process by which object of one class acquire the


properties or features of objects of another class. The concept of inheritance
provides the idea of re-usability. Means we can add additional features to an
existing class without modifying it.

Syntax:
class subclass_name : access_mode base_class_name
{
//body of subclass
};

Data abstraction and Encapsulation: Data abstraction refers to, providing


only essential information to the outside world and hiding their background
details, i.e., to represent the needed information in program without presenting
the details. Encapsulation is an Object Oriented Programming concept that
binds together the data and functions in single unit and that keeps both safe
from outside interference and misuse.

Polymorphism: The word polymorphism means having many forms. In simple


words, we can define polymorphism as the ability of an object to take on many
forms.
Real life example of polymorphism, a person at the same time can have
different characteristic. Like a man at the same time is a father, a husband, an
employee. So the same person possess different behavior in different situations.

Prepared by Md. Masum Billah, Lecturer, Dept of CSE, CBST


This is called polymorphism. Polymorphism is considered as one of the
important features of Object Oriented Programming.

Dynamic binding: Dynamic binding also called dynamic dispatch is


the process of linking procedure call to a specific sequence of code
(method) at run-time. It means that the code to be executed for a
specific procedure call is not known until run-time. Dynamic binding
is also known as late binding or run-time binding.

Message Passing: In Object-Oriented Programming (OOP), message passing is


a way for objects to communicate with each other by sending messages. A
message is a request sent by one object to another object to perform a certain
action or to return some information.
When an object receives a message, it decides how to respond based on its own
internal state and the content of the message. This is known as message
handling or message processing.

Q. “Encapsulation reduces complexity” justify your answer.


The wrapping up of data and functions into a single unit is known as
encapsulation. The data is not accessible to the outside world and only those
functions which are wrapped in that class can access it. Those functions provide
the interface between objects Data and the program. This insulation of the data
from direct access by the program is called Data hiding or information hiding.
As a result data become secured. Thus the encapsulation reduces complexity.
Q. Mention some benefits of OOP.

The principal advantages OOP are as following –


1. Through inheritance, we can eliminate redundant code and extend the use of
existing classes.
2. Encapsulation features that is packing of data & functions into a single
component are to be allowed.
3. The principal of data hiding helps the programmer to build secure programs
that can't be invaded by code in other parts of the program.
4. It is easy to partition the work in a project based on objects.
5. Message passing techniques for communication between objects makes the
interface descriptions with external systems much simpler.
6. Software complexity can be easily managed.

Q. How does object oriented approach differ from object based approach?

Object-oriented and Object-based approach has some different features and


behavior. The main difference between these two approaches.

Object-oriented approach
1. The object-oriented approach supports all the features of OOPs.
2. Object-oriented approach doesn't has an in-built object.
3. Object-oriented languages are C++, C#, Java etc.

Object-based approach
1. Object-based approach doesn't support all the features of OOPs like
Polymorphism and Inheritance.
2. Object-based approach has an in-built object like javascript has a window
object.
3. Object-based languages are Javascript, VB, etc.
Q. Write down the difference between Procedure Oriented Programming
and Object Oriented Programming.
Or, Write down the difference between
Prepared by Md. Masum Structured
Billah, Lecturer, Programming and
Dept of CSE, CBST
Object Oriented Programming.

Difference between Procedure Oriented Programming and Object Oriented


Programming
are as following-
BASIS FOR Procedure Oriented Object Oriented
COMPARISON Programming Programming

Basic Procedure/Structure Object oriented.


oriented.

Approach Top-down. Bottom-up.

Basis Main focus is on "how to Main focus is on 'data


get the task done" security'.

Division Large program is divided Entire program is


into units called functions. divided into objects.

Entity accessing mode No access specifies Access specifies are


observed. "public", "private",
"and protected".

Overloading/Polymorphism Neither has it overloaded It overloads functions,


functions nor operators. constructors, and
operators.

Inheritance There is no inheritance. Inheritance achieved in


three modes public
private and protected.

Data sharing Global data is shared Data is shared among


among the functions in the objects through the
the program. member functions.
BASIS FOR Procedure Oriented Object Oriented
COMPARISON Programming Programming

Example C, VB, FORTRAN, C++, JAVA, VB.NET,


Pascal C#.NET.

Q. Write down the application areas of OOP.

Main application areas of OOP are:

 User interface design such as windows, menu.


 Real Time Systems
 Simulation and Modeling
 Object oriented databases
 AI and Expert System
 Neural Networks and parallel programming
 Decision support and office automation systems etc.

Q. Difference between data abstraction and data encapsulation.

BASIS FOR DATA


DATA ABSTRACTION
COMPARISON ENCAPSULATION

Basic Shows, what elements are Hides the complexity of a


necessary to build a system. system.

Application During 'design level'. During 'Implementation


level'.

Focus Focus is on "what" should Focus is on "how" it should


be done be done.
BASIS FOR DATA
DATA ABSTRACTION
COMPARISON ENCAPSULATION

Achieved Achieved through Achieved through making


encapsulation. the members of a class as
'private'.

Example The GUI of a mobile phone, After the icon is clicked, the
it has some icons to click end user has no idea
on, which on click perform regarding its implementation
the specific function. details

Prepared by Md. Masum Billah, Lecturer, Dept of CSE, CBST

You might also like