Introduction to object oriented programming :
With the rapidly growing world and technology, the human civilization has started demanding more hi-tech software solutions to ease and automate their daily task. We want each and every system to be computerised, so the operations are becoming more and more complex. This causes the increasing complexity of software algorithms. It is seen that traditional programming languages are struggling to produce the output that we demand because of increasing complexity of the software algorithms. To overcome the problems of conventional programming approach, the concept of object oriented programming was introduced.
The latest programming approach, object oriented programming (OOP) offers a very powerful and also an easy way to deal with complexity. The main goal of OOP is to produce clear, reliable and the most importantly easily maintainable programs. The OOP is designed on a certain concept to reach its goal of overcoming the drawbacks of conventional programming approach. In this article, we are going to discuss some basic concept of object oriented programming approach.
The basic concept of object oriented programming :
- Data abstraction
- Data Encapsulation
Objects are the basic identifiable runtime entities in object-oriented programming. Objects may represent a real-world entity like a person, a car, a place, a house etc. For instance, we can say ‘car’ is an object which has some special characteristics like the ‘number of gears’, ‘colour’ etc. and it also holds some functions like ‘braking’, ‘accelerating’ and so on. So, an object represents an entity that can store data and has its interface through functions.
A class is a structure of making a user-defined data type which holds the entire set of data of an object. So, a class is basically a blueprint or a template of a set of objects which shares some common properties and behaviours. We can also say that a class is a collection of similar types objects.
Once a class is created, we can create any number of objects belonging to that class. Actually, a class doesn’t specify any data, it determines the properties or methods that may contain in an object of that class. Classes normally act like a built-in data type, but they are actually a user-defined data types.
For say, ‘Dog’ is a class which holds properties like ‘dog name’, ‘age of the dog’, ‘weight of the dog’ etc. Now, if we have two dogs named ‘Tommy’ & ‘Jenna’, then they will have their own properties like name, age & weight; which may be different for both the dog but they are similar in types. So, the two dogs ‘Tommy’ & ‘Jenna’ will be called as objects of the class ‘Dog’. Here the class ‘Dog’ is representing the common properties of both the two objects named as ‘Tommy’ & ‘Jenna’.
Data Abstraction :
Data abstraction is a concept which hides the background details and represents only the needed information to the outside world. It is the simplification process of real-world concept into its absolutely necessary component.
For example, You are riding a bike, You only know the essential methods to ride a bike like accelerating, braking, how to change the gears, using the clutch etc. but while riding you do you get into internal details of the bike like gearbox, fuel-injection or carburetor, workings of the motor, engine blocks etc ? You just use the accelerator and your bike starts moving, You don’t need to know the details of what happening inside to ride the bike.
This is called abstraction, you only know the essential parts to ride a bike without including the background process or explanation.
Data Encapsulation :
Data encapsulation is one of the most important concepts of object oriented programming. It is a technique which combines both data members and functions, operates on that data in a single unit known as a class. This technique basically prevents the access to the data directly. The only way to access the data is provided by the functions.
If you want to read a data in an object, you have to call the member function in the object. The function will read the data and return the data back to you. So, you have no access to the data directly. Since data is hidden, it is secured from accidental alteration.
For example, consider a big company which may have different departments like production, marketing, sales, account etc. Each department has its own manager to maintain its data. If the production manager wants to know the sales data of last month, the sales department would not be allowed to himself go through the sales department data files. So, he will have to write a letter to the sales department requesting the data required.
Then sales manager will go through the sales data files and sends a reply with asked information. Which implies that data is accessed currently and has no chance of data leak to the outside of that department. This is a real-life example concept of data encapsulation.
Inheritance is also an important characteristic of OOP. It is basically a method which provides a way that capabilities and properties from one class to come into another class. This technique provides code reusability to the programmers. We can form a new class from an existing class, where the existing class contains some properties or methods that also exist in the new class. Here the new class is called as the derived class and the existing class i.e. the class from which the new class is derived is called as the base class.
For instance, ‘vehicle’ is a class with some properties and methods. The ‘car’ and ‘bus’ is also two classes which have some properties and methods that already exist in the class ‘vehicle’. So, both the classes ‘car’ and ‘bus’ can inherit some of its properties from the class ‘vehicle’. So, here the class ‘vehicle’ is a base class and the classes ‘bus’ and ‘car’ are the derived classes of ‘vehicle’.
It is a key to the power of object oriented programming. If a language doesn’t support polymorphism, then it is not in the category of object oriented programming language. Basically, the polymorphism is the ability for a message or data to be processed in more than one form. It is an important concept of object oriented programming which supports the capability of an object of a class to behave differently in response to a message or action.
For a real-life example, consider yourself. At the same time, you may have some different characteristics like a student, a guitarist, a football player. This is called polymorphism, since you have some different forms or characteristics with respect to a different action or situation.
The overloading is also another key concept of object oriented programming language. In one line, we can define overloading as it is the capability of a single function to perform different task depending on the situation. So, the concept of overloading is somehow related to the polymorphism property of OOP. When an existing function or operator is to be operated on new data type, it is called as overloaded.
Overloading allows creating different methods with the same name which differ from each other in the type of the input and the output of the function. It can be used with both functions and members.
- Concept of object oriented programming
- Concept of object oriented programming language
- Concept of object oriented programming in c++
- Basic concept of object oriented programming language
- Basic concepts of object oriented programming with example