Object-oriented programming(OOP) is an approach that binds the data and functions that operate on the data into a single entity. Such an entity is called an object. It protects data from accidental modification from outside functions.
Object orientation is a concept which makes developing of projects easier. Thus the object-oriented programming attempts to solve the problems with only one approach — dividing the problems into submodules and using different objects. Objects of the program interact by sending messages to each other.
Object-oriented programming allows decomposing a problem into a number of objects and then builds data and functions around these objects. Functions of an object can only access its data. One cant access the data directly.
Object-oriented programming was first developed in the 1960s. Simula was the first object-oriented programming language. Java, C++, Visual Basic, .NET, and Ruby are the most popular OOP languages today.
Object-oriented programming is programming that is oriented around objects, thus taking advantage of Encapsulation, Polymorphism, and Inheritance to increase code reuse and decrease code maintenance. For object-oriented programming, an object-oriented language is needed. A language can only be said to be object-oriented if it supports encapsulation, inheritance, and polymorphism.
Basic Concepts of Object-oriented programming:
Class
A class is a prototype that defines the variables and the methods common to all objects of a certain kind. Thus, a class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.
Object
Object is an instance of a class. Objects are the basic runtime entities in an object-oriented system.
Encapsulation
The act of placing data and the operations that perform on that data in the same class is called encapsulation. The class then becomes the ‘capsule’ or container for the data and operations. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it.
Data encapsulation sometimes referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user.
The user can only perform a restricted set of operations on the hidden members of the class by executing special functions commonly called methods.
The concept of data encapsulation is supported in OOP through the use of the public, protected, and private keywords that are placed in the declaration of the class.
Inheritance
Inheritance is the mechanism whereby specific classes are made from more general ones. The child or derived class inherits all the features of its parent or base class and is free to add features of its own.
In OOP, inheritance provides reusability, like, adding additional features to an exciting class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes. In addition, this derived class may be used as the base class of an even more specialized class.
Inheritance provides a clean mechanism whereby common classes can share their common features rather than having to rewrite them.
Polymorphism
Polymorphism(“Poly” means “many” and “morph” means “form”) means the ability to take more than one form. Polymorphism is the property by which the same message or data can be sent to objects of several different classes.
In polymorphism, the classes may contain the same method names but the result which is returned by each method will be different as the code behind each method is different in each class.
The operator or functions are used in different ways, depending on what they are operating on. It is the concept that supports the capability of an object of a class to behave differently in response to a message or action.
Abstraction
Abstraction refers to the act of representing essential features without including the background details or explanation. For example, a person driving a car only knows how to drive a car i.e. the outer details but the inner details about the working of different parts of machinery are hidden from the user.
Message Passing
An object-oriented program consists of a set of objects that communicate with each other via messages. Objects interact and communicate with each other by sending messages to each other. When object A wants object B to perform one of its methods, object A sends a message to object B.
Characteristics of Object-oriented programming:
- Object as a single unit combines both data and functions.
- Functions of an object can only access its data.
- Emphasis is on data rather than procedures.
- One cant access the data directly. It means, data is well secured from outside changes.
- It follows a bottom-up approach in program design.
- Objects communicate with each other through functions.
- New functions and data can be easily added as per requirement.
Benefits Of Object-oriented programming Over Other Programming Languages:
- One of the principal benefits of object-oriented programming techniques over other techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify.
- Inheritance provides reusability, like, adding additional features to an existing class without modifying it. This feature of OOP reduces development time and ensures more accurate coding.
- Since a class defines only the data it needs to be concerned with, when an instance of that class(an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption.
- The definition of a class is reusable not only by the program for which it is initially created but also by other object-oriented programs and for this reason, can be more easily distributed for use in networks. Thus, once functionality is created in one program, it can easily be reused in other programs.
- Object-oriented systems can be easily upgraded from small to large scale.
- It is easy to partition the work in a project based on objects.
- Object-oriented programming offers a new and powerful model for writing computer software. Examples of this software are military defense software, railway booking system, voter registration software, etc.
- It reduces software maintenance and developing costs.
- Changes in user requirements or later developments have always been a major problem. OOP can be the ultimate solution in this case.
- By breaking down complex software projects into small, self-contained, and modular units, object orientation ensures that changes to one part of a software project will not adversely affect other portions of the software.
- It provides a good framework for code libraries, where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
Applications Of Object-oriented programming:
Many complex applications can be built in a simple manner with object-oriented programming. Various applications of OOP are —
- It is used to develop object-oriented databases. These databases store the data directly in the form of objects.
- For implementing knowledge-based or AI systems, OOP is used.
- For implementing the business system or real-time systems, OOP is of great use.
- In the office automation system, object-oriented programming is used.
- For developing applications based on image processing, OOP is used.
- For web-based applications.
- OOP is used for computer-aided design(CAD) and manufacturing.
- OOP is also used for developing computer games such as Diablo, Starcraft, and Warcraft 3. These games offer virtual reality environments in which a number of objects interact with each other in complex ways to give the desired result.
- For distributed computing and applications.
- For data security and management.
- OOP is also used for developing HTML, XHTML and XML documents for the internet. Python, Ruby, and Java are the scripting languages based on object-oriented principles that are used for scripting.
- For pattern recognition, mobile computing, and parallel computing, OOP is of great use.
- OOP is useful in data warehousing and data mining.
- Another popular application of OOP has been in the area of designing graphical user interfaces such as Windows. C++ is mainly used for developing user interfaces.
- Some other areas of application include — Decision support system, Expert system, Neural networks, Computer-assisted concurrent engineering, Computer-aided teaching, and Component-based applications.
Object-oriented programming offers a new and powerful model for writing computer software. This approach speeds the development of new programs and, if properly used, improves the maintenance, reusability, and modifiability of software.