Basic Concepts of Object Oriented Programming

What is Object Oriented Programming?

Object-oriented programming (OOP) is a fundamental programming paradigm used by nearly every developer at some point in their career. OOP is the most popular programming paradigm and is taught as the standard way to code for most of a programmers educational career. OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained.

Example

Following are the Basic Concepts Of OOP

  1. Objects
  2. Classes
  3. Data Encapsulation
  4. Data Abstraction
  5. Inheritance
  6. Polymorphism
  7. Message Passing
  8. Dynamic Binding

1. Object

•Objects are the basic run-time entities in the object-oriented system.
•They may represent a person, a place, a bank account, a table of data etc.
•They may also represent user-defined data such as vectors, time and lists.
•Programming problem is analyzed in terms of objects and the nature of
communication between them.
•Objects take up space in the memory and have an associated address
•Each object contains data and code to manipulate the data

2. Class

•Class is defined as an abstract data type characterized by a set of properties
(attributes and functions) common to its objects
•Class is a user defined data type for object
•Objects are the variables of the type class
•Thus class is a group of objects of similar type
•e.g. Mango, apple, pineapple, orange are objects of class Fruit
•Class is defined first and then objects are created of the type class

3. Data Encapsulation

•The fundamental idea behind OOP approach is to combine the data and
functions operate on that data, into a single unit
•The wrapping up of data and functions into a single unit (called class) is
known as encapsulation
•The data is not accessible to the outside world
•The encapsulation (protection) of Data from direct access by outside
functions in a program is called Data hiding or Information hiding

4. Data Abstraction

•Abstraction refers to the act of representing essential features without
details
•Abstraction is also defined as hiding an implementation details from user
•Classes use the concept of data abstraction and hence they are also known
as Abstract Data Types (ADT)
•Classes are defined as a list of abstract attributes such as size, weight, cost,
and function to operate on these attributes

5. Inheritance

•Inheritance is the process by which objects of one class acquire the
properties of objects of another class
•In OOP, the concept of inheritance provides the idea of reusability
•Reusability allows to add additional features to an existing class without
modifying it
•It is possible by defining a new class from the existing class
•The new class will have combined features of both the classes
•The mechanism of deriving a new class from existing class is called as
Inheritance

6. Polymorphism

•Polymorphism means the ability to take more than one form
•An operation may exhibit different behavior in different instances and
this behavior depends upon the types of data used in the operation
•Polymorphism can be implemented using function overloading,
function overriding and operator overloading
•It allows the objects with different internal structures to share the
same external interface

In the above example all animals are performing the same task of speaking but it is different for every animal.

7. Message Passing

•The Objects communicate with one another by sending and receiving
information (Messages)
•A message for an object is a request for execution of a function
•Message passing involves specifying the name of the object, the name of
the function and the information to be sent

8. Dynamic Binding

•Dynamic binding means that the code associated with a given function
call is not known until run-time.
•The code to be executed is selected at the run-time
•The same function executes different code dynamically depending on
data entered at run-time
•It is associated with polymorphism and inheritance.
•A function call associated with a polymorphic reference depends on the
dynamic type of that reference.