Object oriented design started right from the moment computers were invented. Programming was there, and programming approaches came into the picture. Programming is basically giving certain instructions to the computer.
At the beginning of the computing era, programming was usually limited to machine language programming. Machine language means those sets of instructions that are specific to a particular machine or processor, which are in the form of 0’s and 1’s. These are sequences of bits (0100110…). But it’s quite difficult to write a program or develop software in machine language.
It’s actually impossible to develop software used in today’s scenarios with sequences of bits. This was the main reason programmers moved on to the next generation of programming languages, developing assembly languages, which were near enough to the English language to easily understand. These assembly languages were used in microprocessors. With the invention of the microprocessor, assembly languages flourished and ruled over the industry, but it was not enough. Again, programmers came up with something new, i.e., structured and procedural programming.
Structured Programming –
The basic principle of the structured programming approach is to divide a program into functions and modules. The use of modules and functions makes the program more understandable and readable. It helps to write cleaner code and to maintain control over the functions and modules. This approach gives importance to functions rather than data. It focuses on the development of large software applications, for example, C was used for modern operating system development. The programming languages: PASCAL (introduced by Niklaus Wirth) and C (introduced by Dennis Ritchie) follow this approach.
Procedural Programming Approach –
This approach is also known as the top-down approach. In this approach, a program is divided into functions that perform specific tasks. This approach is mainly used for medium-sized applications. Data is global, and all the functions can access global data. The basic drawback of the procedural programming approach is that data is not secured because data is global and can be accessed by any function. Program control flow is achieved through function calls and goto statements. The programming languages: FORTRAN (developed by IBM) and COBOL (developed by Dr Grace Murray Hopper) follow this approach.
These programming constructs were developed in the late 1970s and 1980s. There were still some issues with these languages, though they fulfilled the criteria of well-structured programs, software etc. They were not as structured as the requirements were at that time. They seem to be over-generalised and don’t correlate with real-time applications.
To solve such kinds of problems, OOP, an object-oriented approach was developed as a solution.
The Object-Oriented Programming (OOP) Approach –
The OOP concept was basically designed to overcome the drawback of the above programming methodologies, which were not so close to real-world applications. The demand was increased, but still, conventional methods were used. With the emergence of OOP, all conventional methods were thrown out the window. OOP methodology not only solved the modern-era problem, but also, it brought a revolution in the programming methodology field.
Object-oriented programming (OOP) is nothing but that which allows the writing of programs with the help of certain classes and real-time objects. We can say that this approach is very close to the real-world and its applications because the state and behaviour of these classes and objects are almost the same as real-world objects.
Let’s go deeper into the general concepts of OOP, which are given below:
What Are Class & Object?
It is the basic concept of OOP; an extended concept of the structure used in C. It is an abstract and user-defined data type. It consists of several variables and functions. The primary purpose of the class is to store data and information. The members of a class define the behaviour of the class. A class is the blueprint of the object, but also, we can say the implementation of the class is the object. The class is not visible to the world, but the object is.
Here, the class car has properties car_id, colour, engine_no and distance. It resembles the real-world car that has the same specifications, which can be declared public (visible to everyone outside the class), protected and private (visible to none). Also, there are some methods such as distance_travelled(), petrol_used(), music_player() and display(). In the code given below, the car is a class and c1 is an object of the car.
Data Abstraction –
Abstraction refers to the act of representing important and special features without including the background details or explanation about that feature. Data abstraction simplifies database design.
- Physical Level:
It describes how the records are stored, which are often hidden from the user. It can be described with the phrase, “block of storage.”
- Logical Level:
It describes data stored in the database and the relationships between the data. The programmers generally work at this level as they are aware of the functions needed to maintain the relationships between the data.
- View Level:
Application programs hide details of data types and information for security purposes. This level is generally implemented with the help of GUI, and details that are meant for the user are shown.
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit, e.g., a class in Java. This concept is often used to hide the internal state representation of an object from the outside.
Inheritance is the ability of one class to inherit capabilities or properties of another class, called the parent class. When we write a class, we inherit properties from other classes. So when we create a class, we do not need to write all the properties and functions again and again, as these can be inherited from another class which possesses it. Inheritance allows the user to reuse the code whenever possible and reduce its redundancy.
Polymorphism is the ability for data to be processed in more than one form. It allows the performance of the same task in various ways. It consists of method overloading and method overriding, i.e., writing the method once and performing a number of tasks using the same method name.
Some important points to know about OOP:
- OOP treats data as a critical element.
- Emphasis is on data rather than procedure.
- Decomposition of the problem into simpler modules.
- Doesn’t allow data to freely flow in the entire system, ie localized control flow.
- Data is protected from external functions.
Advantages of OOPs –
- It models the real world very well.
- With OOP, programs are easy to understand and maintain.
- OOP offers code reusability. Already created classes can be reused without having to write them again.
- OOP facilitates the quick development of programs where parallel development of classes is possible.
- With OOP, programs are easier to test, manage and debug.
Disadvantages of OOP –
- With OOP, classes sometimes tend be over-generalised.
- The relations among classes become superficial at times.
- The OOP design is tricky and requires appropriate knowledge. Also, one needs to do proper planning and design for OOP programming.
- To program with OOP, the programmer needs proper skills such as that of design, programming and thinking in terms of objects and classes etc.
- Object Oriented Programming (OOPs) Concept in Java
- Characteristics of Good Object Oriented Design
- Differences between Procedural and Object Oriented Programming
- Basic Concepts of Object Oriented Programming using C++
- OOPS | Generalization as extension and restriction using Java
- Service-Oriented Architecture
- HTML | DOM Object Object
- Layouts in Android UI Design
- Design a Keylogger in Python
- 6 Best CSS frameworks You should Know to design Attractive Websites
- Design Issues of Distributed System
- Computer Organization | Control Unit and design
- Design an online book reader system
- Design data structures for a very large social network like Facebook or Linkedln
- HTML | DOM Map Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.