Fundamentals of Object Oriented Programming Procedure Oriented Programming (POP)
Fundamentals of Object Oriented Programming Procedure Oriented Programming (POP)
POP characteristics
OOP’s chief concern is to hide the data from non-member functions of a class, which it treats
like “critical information”. Data is closely tied to the member functions of a class, which operates
on it. It doesn’t allow any non-member function to modify the data inside it. Objects interact with
each other through member functions to access their data.
An object is referred to as a data field that has unique attributes and behavior. Everything in
OOP is grouped as self-sustainable objects.
OOP is the most popular programming model among developers. It is well suited for programs
that are large, complex, and actively updated or maintained. It simplifies software development
and maintenance by providing major concepts such as abstraction, inheritance, polymorphism,
and encapsulation. These core concepts support OOP.
OOP characteristics
● Everything is an object
● Developer manipulates objects that uses message passing.
● Every object is an instance of a class.
● The class contains the attribute and behavior associated with an object.
3. OOPs provides the ability to simulate real-world event much more effectively. We can
provide the solution of real word problem if we are using the Object-Oriented
Programming language.
There are various object-oriented programming languages are present. But we have enlisted
some popular and widely used OOP languages. According to the TIOBE index, the top twenty
OOP languages are Java, C++, C#, Python, R, PHP, Visual Basic.NET, JavaScript, Ruby, Perl,
Object Pascal, Objective-C, Dart, Swift, Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk.
Applications of OOPs
Basis Main focus is on "how to get the task Main focus is on 'data security'.
done" i.e. on the procedure or Hence, only objects are permitted
structure of a program . to access the entities of a class.
Division Large program is divided into units Entire program is divided into
called functions. objects.
Data hiding & There is no proper way of hiding the Data is hidden in three modes
security data, so data is insecure public, private, and protected.
hence data security increases.
Data sharing Global data is shared among the Data is shared among the objects
functions in the program. through the member functions.
Example C, Visual Basic (VB), FORTRAN, C++, JAVA, Python, C#, Visual
Pascal Basic.NET.
Principles of OOP
The following are the principles of OOP, that a object oriented programming language should
support:
1. Class
2. Objects
3. Data Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic Binding
8. Message Passing
1. Class:
A class is a user-defined data type. It consists of data members and member functions, which
can be accessed and used by creating an instance of that class. It represents the set of
properties or methods that are common to all objects of one type. A class is like a blueprint for
an object.
For Example: Consider the Class of Cars. There may be many cars with different names and
brands but all of them will share some common properties like all of them will have 4 wheels,
Speed Limit, Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage
are their properties.
2. Object:
It is a basic unit of Object-Oriented Programming and represents the real-life entities. An Object
is an instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated. An object has an identity, state, and
behavior. Each object contains data and code to manipulate the data. Objects can interact
without having to know details of each other’s data or code, it is sufficient to know the type of
message accepted and type of response returned by the objects.
For example “Dog” is a real-life Object, which has some characteristics like color, Breed, Bark,
Sleep, and Eats.
3. Data Abstraction:
Data abstraction is one of the most essential and important features of object-oriented
programming. Data abstraction refers to providing only essential information about the data to
the outside world, hiding the background details or implementation.
Consider a real-life example of a man driving a car. The man only knows that pressing the
accelerators will increase the speed of the car or applying brakes will stop the car, but he does
not know about how on pressing the accelerator the speed is increasing, he does not know
about the inner mechanism of the car or the implementation of the accelerator, brakes, etc in the
car. This is what abstraction is.
4. Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that
binds together code and the data it manipulates. In Encapsulation, the variables or data of a
class are hidden from any other class and can be accessed only through any member function
of their class in which they are declared. As in encapsulation, the data in a class is hidden from
other classes, so it is also known as data-hiding.
5. Inheritance:
6. Polymorphism:
The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form. For example,
A person at the same time can have different characteristics. Like a man at the same time is a
father, a husband, an employee. So the same person posses different behavior in different
situations. This is called polymorphism. (Refer to the figure, for types of polymorphism)
7. Dynamic Binding:
In dynamic binding, the code to be executed in response to the function call is decided at
runtime. Dynamic binding means that the code associated with a given procedure call is not
known until the time of the call at run time. Dynamic Method Binding One of the main
advantages of inheritance is that some derived class D has all the members of its base class B.
Once D is not hiding any of the public members of B, then an object of D can represent B in any
context where a B could be used. This feature is known as subtype polymorphism.
8. Message Passing:
Where is it used?
OOP is often the best use when we are dealing with manufacturing and designing applications.
It provides modularity in programming. It allows us to break down the software into chunks of
small problems that we then can solve one object at a time.
It should be used where the reusability of code and maintenance is a major concern. Because it
makes development easy and we can easily append code without affecting other code blocks. It
should be used where complex programming is a challenge.
Object-based programming language is one that supports the first four OOP principles (class,
objects, data abstraction, encapsulation) sometimes support polymorphism, but not inheritance
are termed as object-based languages. JavaScript and VBScript are examples of object-based
programming languages.