Object Oriented Programming
Object-oriented programming (OOP) is a programming paradigm based on the
concept of objects.
Objects can contain data (called fields, attributes or properties) and have actions
they can perform (called procedures or methods and implemented in code).
Difference between procedure oriented programming and Object oriented
programming.
Basic Concepts of OOP’s
The following are the major characteristics of OOP’s:
Objects
Class
Abstraction
Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Objects
Objects are basic building blocks for designing programs.
An object is a collection of data members and associated member functions.
An object may represent a person, place or a table of data.
Each object is identified by a unique name. Each object must be a member of a
particular class.
Example: Apple, orange, mango are the objects of class fruit.
Objects take up space in memory and have address associated with them.
At the time of execution of a program, the objects interact by sending the messages
to one another.
The objects can interact with one another without having to know details of data or
functions within an object.
Classes:
The objects can be made user defined data types with the help of a class.
A class is a collection of objects that have identical properties, common
behavior and shared relationship.
Once class is defined, any number of objects of that class is created.
Classes are user defined data types. A class can hold both data and
functions.
For example: Planets, sun, moon are member of class solar system.
Abstraction:
Data Abstraction refers to the process of representing essential features
without including background details or explanations.
Encapsulation:
The wrapping of data and functions into a single unit (class) is called
data encapsulation.
Data encapsulation enables data hiding and information hiding.
Data hiding is a method used in object oriented programming to hide
information within computer code.
Inheritance:
Inheritance is the process by which one object can acquire and use the properties
of another object.
The existing class is known as base class or super class.
The new class is known as derived class or sub class.
The derived class shares some of the properties of the base class. Therefore a code
from a base class can be reused by a derived class.
Polymorphism
Polymorphism means "same thing in many forms".
It allows one method, function, or operator to behave differently in different
situations.
It can be achieved by Overloading and Overriding,
Dynamic Binding (Late Binding)
The code to be executed is decided at runtime, not at compile time.
It allows for flexible and reusable code.
Message Passing:
Objects communicate with each other by sending and receiving messages (function calls).