Object Oriented Programming Concepts

In the last article, we mentioned C++ as an object oriented language. The brief explanation to our consideration is defined here.

OOP is a design philosophy. It stands for Object Oriented Programming. Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages (C, Pascal, etc.). Everything in OOP is grouped as self sustainable “objects”. Hence, you gain re-usability by means of four main object-oriented programming concepts. The term object oriented means that we organize a problem as a collection of discrete objects that contains data and functions that operate on that data. Before proceeding to further let us briefly study the object oriented programming concepts-

Object:

This is the basic unit of object oriented programming. An object is an entity that has state, behavior and property. Objects are used to model real world entities that we find in the daily life. That is both data and function that operate on data are bundled as a unit called as object. Every object will have data structures called attributes and behavior called operations.

Class:

When you define a class, you define a blueprint or template for an object. A class is a group of objects with same attribute and common behaviours. Now we can say that object is the instance of a class. For example, Furniture is a class and sofa, chair,table are its objects.

Remarks: The difference between C++ classes and C structures are that by default all structure members are public whereas classes members are private.

Abstraction:

Data abstraction refers to hiding complexity and providing only essential information to the outside word. It hides  their background details ie. to represent the needed information in program without presenting the details.  C++ classes provides different methods to the outside world without giving internal detail about those methods and data.

Encapsulation:

Encapsulation is the wrapping up of data and related functions in a single unit called object. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object. It keeps the data safe from external interference and misuse.

Inheritance:

One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. The base class is also called as parent or super class and derived class is also known as child or sub class.

Polymorphism:

The word polymorphism is derived from two Greek words POLY which means many and MORPHOS which means forms. As the name suggests, it is the ability to use the same name for two or more related but technically different tasks. It can be categorized into two sub parts-

  • Compile time Polymorphism
  •  Run time Polymorphism.

Now you have become familiar with Object oriented concepts. Let us now discuss the difference between Procedural language and Object Oriented Programming language:

Procedural language:

  • It divides the problem into functions
  • It lays more emphasis on functions
  • Data is global and accessible to all functions of the program without any restriction
  • Represent non real world modeling
  • Follows top down approach
  • Functions communicate with each other through passing parameters
  • Lays more emphasis on how to solve a given problem rather than what to do.
  • Ex: C, Pascal, Basic etc.

Object oriented Programming language:

  • It divides the problem into number of entities called objects.
  • It lays more emphasis on data rather than functions
  • Data and associates functions are bind together in single unit.
  • Represent real world modeling
  • Follows bottom up approach
  • Objects communicate with each other through passing messages.
  • Lays more emphasis on what to do in order to solve a given problem.
  • Ex: C++,Ada, Simula, Java