This document provides an overview of object-oriented programming concepts. It discusses procedural programming versus object-oriented programming. It then describes key characteristics of OOP like objects, classes, encapsulation, abstraction, inheritance, polymorphism, and message passing. Objects are runtime entities that have state and behavior. Classes provide blueprints for objects and define their properties and methods. Encapsulation hides implementation details, while abstraction exposes only necessary details. Inheritance allows classes to inherit properties from other classes. Polymorphism allows the same method name to perform different tasks. Message passing allows objects to communicate by sending and receiving messages.
2. PROCEDURAL LANGUAGE AND OBJECT
ORIENTED APPROACH
Procedural Oriented Programming Object-Oriented Programming
In procedural programming, the program is
divided into small parts called functions.
In object-oriented programming, the
program is divided into small parts
called objects.
There is no access specifier in procedural
programming.
Object-oriented programming has access
specifiers like private, public, protected,
etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any
proper way of hiding data so it is less secure.
Object-oriented programming provides
data hiding so it is more secure.
In procedural programming, overloading is
not possible.
Overloading is possible in object-oriented
programming.
In procedural programming, the function is
more important than the data.
In object-oriented programming, data is
more important than function.
Code reusability absent in procedural
programming,
Code reusability present in object-oriented
programming.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
3. CHARACTERSTICS OF OOPS
Object-oriented programming (OOP) has become one of the most popular
programming paradigms at the current time. Almost every major programming
language provides some form of OOP support, making it a very accessible option
for programmers of various levels and domains.
4. OBJECTS
In C++, Object is a real world entity, for example, chair, car, pen,
mobile, laptop etc.
In other words, object is an entity that has state and behavior. Here,
state means data and behavior means functionality.
Object is a runtime entity, it is created at runtime.
Student s1; //creating an object of Student
Let's see an example to create object of student class using s1 as the reference
variable.
In this example, Student is the type and s1 is the reference variable
that refers to the instance of Student class.
5. CLASSES
The next characteristic of object-oriented programming is the definition of classes.
A class is where the blueprint for an object is defined. The blueprint defines the
methods, attributes, and other aspects of the object. Objects are created from
classes. A class is also known as a blueprint for an object. It defines properties,
methods, and other aspects associated with the object. Objects are created from
classes. A class is essentially a blueprint for an object. It defines properties,
methods, and other aspects associated with the object.
6. ENCAPSULATION
Another characteristic of OOP is that it emphasizes the encapsulation of data and
functionality within objects. Objects are defined with specific functionality that
governs the interactions between the objects. Encapsulation of data is an
extremely important aspect of OOP. This is because it prevents hackers from
modifying data that is stored in the database
7. Abstraction
If you are a user, and you have a problem statement, you don't want to
know how the components of the software work, or how it's made. You only
want to know how the software solves your problem. Abstraction is the
method of hiding unnecessary details from the necessary ones. It is one of
the main features of OOPs. For example, consider a car. You only need to
know how to run a car, and not how the wires are connected inside it. This
is obtained using Abstraction
8. INHERITANCE
Inheritance means inheriting someone's characteristics. Just like you inherit
features and habits from your parents, it is possible to inherit the data and
methods from one class to another. Combining and inheriting the objects and
their properties is one of the most essential and important characteristics of
oops.
Super Class: The class from which the properties are inherited by the sub
class/child class.
Sub Class: The class which inherits the properties from the super
class/parent class.
Inheritance helps you do the separation of the same fields and functionality
so that it can be reused in other classes. And this helps in code redundancy.
Composition
Composition is the procedure of combining two or more objects together
to create a new and unique object. Through this process developers find it
easy to reuse the elements specifically needed for the object to create a
new and unique object
9. POLYMORPHISM
Polymorphism means to have the same name of a method performing different
tasks. For example, in finding out the area of the shape, the area of the square is
length2, and the area of the rectangle is length*breadth.
It has the ability to display the message in more than one form. A person can
possess different characteristics at the same time, so this is what polymorphism is
all about.
10. Polymorphism exhibits two different
behaviors
Static Polymorphism/ Method Overloading: It occurs when methods with the
same name have differences in the number and types of parameters.
For example:
Explanation:
Both Person and Child classes have the
same method, i.e., walks(), and the Child
class overrides the walks() method by
having its own implementation.
OUTPUT :-
11. Static Polymorphism/ Method Overloading: It
occurs when methods with the same name have differences in the number and
types of parameters.
Explanation:
In the above code, the show() method is
overloaded by changing the number of
parameters as well as by changing the name
of the data type. So this is known as Method
Overloading.
Polymorphism has the ability to perform
different tasks with the same method, due
to which the code is clean.
OUTPUT:-
12. Data Binding
Binding means to bind one thing to another one. Here in OOPS, binding refers to
linking some attribute of one object to another one in the Application.
There are two main types of binding:
Static Binding
Dynamic binding
Let's understand both of them using an example.
Static Binding
In static binding, the property of one object is changed directly without changing
the other property.
13. OUTPUT:-
Explanation
When any type of object
is determined at the
compile time, then it is
known as static binding.
Also, play() and walks()
are private methods, and
that is the reason for
the static binding.
14. Dynamic Binding
When any object is determined at the run time, then it is known as dynamic
binding.
Dynamic Binding occurs when the property of one object changes, and due to
this, the property of another object gets changed.
OUTPUT:-
Explanation
In the above code, the instance of Child
is also an instance of Person, So the
compiler can't determine the object
type.
15. MESSAGE PASSING
Passing data around the program is the most important feature of the oop concept.
Message passing is the sending of a message from one object to another. How does
this occur?
As we know that each object has its own specific address that other objects can use
to send messages. Now that object can do whatever it needs to do based on the
message. Multiple objects can communicate with each other in interesting ways.