Object Oriented Programming

Object Oriented Programming

The object oriented programming ( also referred as OOP ) is an approach to the programming that is based on the concept of object and class.

The OOP programming paradigm was developed  in order to overcome the limitations of the procedural programming.

Most students begin their programming journey with the conventional procedural programming language such as C language.

However , the procedural programming had some major limitations. In conventional procedural programming, It was difficult to develop a large complex software.

The OOP program organization allows the programmer to protect the key data elements. The data can be protected by restricting its access to only methods that belong to the object.

What Is Object Oriented Programming ?

The OOP programming approach views the program components in the form of objects. Each object can have its own data and the methods that can operate on the data.

In this tutorial, you will learn what is object oriented programming , some important fundamental OOP concepts such as the concept of class and the objects.

We will also discuss in detail the four important fundamental OOP program principles which include the design principle encapsulation, inheritance, abstraction and polymorphism.

Let us first start with understanding the need that led to the development of OOP programming paradigm.

Object Oriented Programming In Java , Java Programming Basics

Object Oriented Programming ( OOP )

Table Of Contents

Need For OOP Programming Approach

The conventional procedural programming approach had some major limitations. In conventional procedural programming, It was difficult to adequately secure the program data from inadvertent changes.

The typical procedural program structure consist of program data in the form of variables and the functions that operates on the data.

The program data in the procedural programming is generally global. The global data can be operated upon by any function. It was difficult to protect the data from such inadvertent changes.

The unrestricted access to the program data makes it venerable because the  data can be easily modified by any function.

Such change in the global data can adversely affect the functionality of other functions that also use the same data.

Procedural Program

The object oriented programming ( OOP ) approach provided the much needed solution to the limitations of the procedural programming.

In OOP programming approach , it was much easier to control the access to the data. It also became much easier to model the real world objects in the OOP programming style.

What Is Object Oriented Programming ?

The object oriented programming is an approach ( programming paradigm ) to the software application development that is based on the fundamental concept of class and object.

In OOP methodology , all the program components  are represented as objects into the program code. The objects are defined as class in the program code.

For example, the student , instructor , course , department are few examples of the objects in case of software application for the college.

What Is Object Oriented Programming

In OOP program , we combine the group of variables related to the object and the methods to operate on the data as a single unit.

An object is the smallest component in the OOP program. Each object has some State ( Properties ) and behavior ( Methods ).

Object Oriented Programming

What Is Object In OOP ?

The object is a real world entity that needs to be represented into the software application. The world around us is full of objects such as pen , lamp , house , car , cat , dog are all examples of object.

However , for software application development point of view an object could be either living entity , physical object or even business concept such as bank account.

Each object has unique identity and a state. The state of an object is defined by its member variables. The object behavior is defined by its member methods.

Concept Of Object In OOP
OOP Program

The objects are runtime entities created during the program execution. To create an object , the resources are required in terms of memory allocation.

The programmer has to first define the object in the form of a class. A class works as a template for the object.

For example, we can instantiate ( create ) as many student objects from the student class defined in the program code.

Example Of Object In OOP

The OOP program can have may objects. Each object can be uniquely identified by its identity and state.

The objects methods describe what all operations that object can perform.

What Is Object In OOP

Object Oriented Programming

Object State

Each object has a state that is defined by its properties ( Data ). The object properties are represented by the data ( also referred as variables ).

The state of an object is described by its properties ( data ) . Each object has its own set of data.

Object Behavior

Each object has also exhibits some behavior. The object behavior defined by its methods.

The object behavior is represented by the methods. The programmer can define number of methods in the class.

Object Unique Identity

Each object in the OOP program has a unique identity. The programmer can change the object properties and methods as per the program requirements.

For example , let us consider an example of a car object. Each car can be individually identified by its unique registration number , chases number and the owner details.

Object Properties And Methods

The properties and methods are essential components for an object. The object properties are represented by the variables ( data ). Whereas the objects behavior in terms of operations is defined by its methods.

Concept Of Object Properties And Methods

Object Oriented Programming

What Is Class In OOP ?

A class is defined as a blueprint for creating an object. A class can also be alternately referred to as template that describes an object.

A class is a mechanism in the OOP that binds the variables and methods together related to an object.

The programmer can define the visibility of the class variables and methods by using access specifier. The public variables and methods can be accessed from anywhere in the program code.

In OOP methodology , the program code is organized in the form of set of classes. The class defines the object in the program code.

Concept Of Class In OOP

What Is Class In OOP

Each and every class represents a real world entity. In other words, an object  that needs to be represented in the program code.

The OOP programming methodology  clearly defines the data ownership in terms of classes . Each class binds together  the data and the methods that operate on the data.

Example Of Class In OOP

Let us consider one example of a class declaration in Java. The class is declared by using a Java keyword class. In this example , we have declared a class with MethdDemo as class name.

Object Oriented Programming Example , Java Program

OOP Principles

Principles Of Object Oriented Programming

The OOP programming organization is based on the four major fundamental principles . The OOP principles include :

1. Encapsulation

2. Inheritance

3. Abstraction

4. Ploymorphism

Principles Of Object Oriented Programming

Object Oriented Programming

1. Encapsulation

What Is Encapsulation In OOP ?

The process of binding the data and methods together as a single unit is referred as encapsulation .

Lack of adequate data security was one of the major limitations of the procedural programming.

The unrestricted access to the data makes it venerable to the inadvertent changes. And  such changes in the data can affects the outcome of the functions that share the same data.

And therefore , in OOP programming , the data access is restricted to the methods that belongs to the object.

What Is Encapsulation In OOP

Object Oriented Programming

2. Inheritance.

What Is Inheritance In OOP ?

The inheritance is the process of acquiring the existing functionality  of the parent class and adding additional features and functionality in to the inherited  child class. 

The inheritance in OOP is the process of deriving one class from another class is  referred as inheritance. The inherited class effectively function as parent class and the inherited class is referred as child class.

The inheritance is one of the most important fundamental principle in the OOP programming paradigm . The inheritance basically deals with the re-usability of the program code.

For example , the single inheritance and multi-level inheritance is allowed in Java.

What Is Super Class ?

Base Class Or Parent Class.

A class is said to be a super class when it is inherited by one or more classes. The super class is also alternately referred to as base class or parent class.

What Is Sub Class ?

Child Class Or Derived Class.

A class is said to be a sub class when it is derived from another class. The sub class is also alternately referred to as child class or derived class.

The derived class once crated will have its own copy of the variables and methods declared in the parent class.

However , the sub class can add and declare more variables and methods in addition to the inherited variables and methods from the parent class.

Types Of Inheritance In OOP

Single Inheritance , Java Tutorial
Multilevel Inheritance , Java Tutorial

The re-usability of the code is an important feature of the object oriented programming. The code re-usability allows the programmer to use already created classes in the program code.

By using inheritance, the programmer make use of the existing code already previously written and tested for other projects. The inheritance  helps  to  reduce the  overall development time for the software development.

What Is Not Allowed ?

For example , the hybrid inheritance and multiple inheritance is NOT allowed in Java.

Hybrid Inheritance
Multiple Inheritance , Java Programming Basics

Object Oriented Programming

3. Abstraction.

What Is Abstraction In OOP ?

The term abstraction is another important fundamental principle in OOP. The term abstraction in OOP simply means presenting simplified view and hiding the complexity.

The word abstract  is taken from a Latin word  meaning “pulled away, detached,”. The basic idea in abstraction is of something detached from the actual physical object.

The abstraction is frequently used to convey ideas. It simply means that it does not have a clear applicability to real life specific object. It means it doesn’t pictorially  represent  a specific real life object.

 The concept of abstraction  is  used  in the OOP program to present  a more simplified  view  of  an object  by removing the irrelevant details.

Abstraction In Java , Java Programming Basics
Abstraction In Java , Java Programming Basics

The concept of abstraction has many applications. In software engineering , It is used to facilitate the understanding of the complex software systems.

The abstraction is especially essential in solving complex problems as it enables the problem solver to think in terms of conceptual ideas rather than in terms of any specific object.

Example Of Abstraction In OOP

A  class that is declared using “abstract” keyword is known as abstract class. The abstract class may or may not include abstract methods.

Which in other words, It means that in abstract class we can also define the concrete methods . A method is said to be concrete when it has a method body and its implementation.

An abstract class can also contain abstract methods. A method is said to an abstract method when the method does not have a method body and its implementation.

Abstract Class In Object Oriented Programming
Abstract Class In OOP

An abstract class cannot be instantiated . Which means we cannot create an object of the abstract class.

The abstract class can be inherited by the child class and provide implementation details for the abstract methods.

Object Oriented Programming

4. Polymorphism.

What Is Polymorphism In OOP ?

The  polymorphism is one the four fundamental OOP principle design concepts  used  extensively  in  the object oriented programming.

The word polymorphism consist of two Greek words poly and morph . The word  poly means many and the word morph means forms. The term polymorphism  simply  means  many forms.

The polymorphism can also be defined as  single object with multiple different behavior. The polymorphic behavior of the object depends upon the context.

The most common use of polymorphism in OOP occurs when a parent class   reference  is used   to   refer to  a  child class  object.

The most common and simple use of polymorphism in OOP program  is use of  the same method name .

For example, It is possible to define  many methods  with  the  same method name but with different implementation.

What Is Polymorphism In OOP

The  correct method  would be invoked  depending upon the manner in which the method is invoked.

 The decision to invoke the appropriate method can either happen at compile time Or it can happen during the run time . This is referred as compile time polymorphism and runtime polymorphism respectively.

Object Oriented Programming

OOP Advantages

Advantages Of Object Oriented Programming

The object oriented programming offers many advantages as compared to its predecessors such as procedural programming.

Advantages Of Object Oriented Programming

OOP Can Support Large Software Project.

The procedural programming languages had some major limitations while designing a large scale software.

The object oriented programming can easily handle large scale and complex software development project.

OOP Offers Better Data Protection.

The OOP programming paradigm offers many features that provide excellent data protection. In OOP , the data access permissions are tightly controlled.

The OOP programming allows programmer to define and set the data access permissions. The OOP languages offer many access modifiers to  achieve the desired access level.

Code Re-Usability.

The code re-usability is an important feature of all object oriented programming languages.

The programmer can create a library of the standard classes to handle the commonly used functionality.

Else, it is also possible to use the standard class library methods by simply including these class library into the program code.

Better Representation Of Real world Objects

The OOP programming is based on the fundamental concept of object and class. The object represents a real world entity.

The OOP programming allows programmer to describe an object features into the class. The programmer can easily represent real world objects realistically into the program code.

Better Software Maintenance.

The software maintenance is a big challenge for the most software companies. However , the OOP program is relatively much easier to manage in the long run.

The routine code maintenance issues can be easily resolved in the OOP. The basic modular design allows the programmer to incorporate the necessary changes into the program code.

Enhanced Security.

The OOP languages offer robust security features. The OOP programming languages offer excellent security features that allows the programmer to incorporate the necessary security features.

The OOP based programming languages like Java. For example Java language does not support the pointers which gives direct access to the memory.

Easy Code Modification

The software programs are designed to service the end user for a long time. In most situations the all software need to be modified by  incorporating the changes into the software. Such changes can crate a software bug.

However , the OOP language based software can easily be modified due to its modular structure without adversely affecting the functionality of other modules.

OOP Languages

List Of Of Object Oriented Programming Languages

The list of programming languages that support the object oriented programming include some of the most popular programming languages.

Java

C++

Python

Ruby

JavaScript

PHP

C# 

Perl

VB.Net

Dart

Object Pascal

R

Scela

Kotlin

Objective C

Swift

Common Lisp

MATLAB

Smalltalk

Join The Best Seller

Computer Science Online Course

This is the most comprehensive  and unique  Computer Science  And Programming Fundamentals course Online which will give you in depth understanding of most important fundamental concepts in computer science And Programming .

Don`t copy text!