Basic Concepts of Object Oriented Programming

September 12, 2015 Posted by WithU Technologies
Instructor: The basic concepts of Object Oriented programming are described below which will help you to understand the essence of OOP concept.

  • Objects

Objects are the basic runtime entities which represent a person, a place, a bank account, a table of data or any item that the program has to be handle. They may also represent by a user defined data such as vectors, time and lists. Thus, programming problems are analyzed in terms of objects by matching them with the real world objects. The defined objects take up space in memory and have an associated address.



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 the type of response returned by the objects

  • Classes

In the above example of Object as a student. Data are defined as Name, date of Birth and Marks. As like that user define the data type also with the help of classes. Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created. A class is thus a collection of objects of similar type. For example, Rose, Daisy and Marigold are members of the class Flowers. Classes are user-defined data types and behave like the built-in types of a programming language- The syntax used to create an object is no different than the syntax used to create an integer object in C. If flower has been defined as a class, then the statement:

flower rose;

will create an object named rose belonging to the class flower.

  • Data Encapsulation

The wrapping up of data and functions into a single class is known as encapsulation. The data is not accessible to the outside applications or classes, and only those functions which are wrapped in the same class can access it. It treats data as a critical element in the program development and does not allow it to flow freely around the system.

  • Data Abstraction

The Classes which are represents without any background details or explanations. Such as, size, weight and cost which are defined as list of abstract attributes.

Let's took an example of airplane. You travel through airplanes from one place to another. But you don't know about their internal functionality that how they took off and how they fly over the ground. Thus, we can say that an airplane separates its internal implementation from its external interface.



In case of C++ you might be familiar with the COUT command which print out or displays text on the output screen. Here you don't need to understand how COUT displays text. You only need to know the underlying interface and public implementation of COUT is free to change. We use Classes to define our own Abstract Data Types (ADT).

  • Inheritance

Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical Classification. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

For example, the Bicycle now becomes the superclass of Mountain Bike, Road Bike, and Tandem Bike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:



Thus, inheritance introduces the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by the concept of inheritance where the main class or existing class derive its features from main class. So, the new class will have the combined features of both the Super class and the Sub class.

Note that each sub-class defines only those features that are unique to it. Without the use of classification, each class would have to explicitly include all of its features.

  • Polymorphism

Polymorphism, a Greek term, means the ' ability to take more than one form. An operation may exhibit different behaviors in different instances. It refers to a principle of biology in which an organism or species can have different life forms or stages.

The behavior depends upon the types of data used in the operation.

For example, consider the operation of addition. For two numbers, the operation will generate a sum.

If the operands are strings, then the operation would produce a third string by concatenation.

The process of making an operator to exhibit different behaviors in different instances is known as operator overloading.

This is something similar to a particular word having several different meanings depending on the context. Using a single function name to perform different types of tasks is known as function overloading.

Polymorphism plays an important role in allowing objects having different internal structures to share the same external interface.

  • Dynamic Binding

It is associated with Polymorphism and inheritance where the code associated with a given procedure is not known until the time of the call at run-time.



For instance, here the Main class is Shape which initializes a procedure called Draw. By inheritance every object have this procedure. Its algorithm is, however, unique to each object and so the draw procedure will be redefined in each class that defines the object. At run-time, the code matching the object under current reference will be called.

  • Message Passing

Message passing involves specifying the name of the object, the name of the function (message) and the information to be sent. Objects communicate with one another by sending and receiving information much the same way as people pass messages to one another.

Objects have a life cycle. They can be created and destroyed. Communication with an abject is feasible as long as it is alive.

Object-Oriented technology offers several benefits over the conventional programming method, the most important one being the reusability.

Applications of OOP technology has gained importance in almost all areas of computing including real-time business systems.

There are a number of languages that support object-oriented programming paradigm. Popular among them are C++, Smalltalk and Java. C++ has become an industry standard language today.