Object-oriented design has been around since the invention of computers. There was programming, and programming methods were born. Programming is basically giving instructions to a computer.

At the beginning of the computing era, programming was usually limited to machine language programming. Machine language refers to those instruction sets, of the form 0 and 1, that are specific to a particular machine or processor. These are bits (0100110…) . But writing programs or developing software in machine language is very difficult.

It is virtually impossible to develop software using bit sequences in today’s scenarios. This is the main reason programmers are turning to the next generation of programming languages to develop assembly languages, which are close enough to English to be easy to understand. These assembly languages are used in microprocessors. With the invention of the microprocessor, assembly language flourished and dominated the entire industry, but it was not enough. Again, programmers came up with something new: structured and procedural programming.

Structured programming —

The basic principle of structured programming is to divide programs into functions and modules. The use of modules and functions makes the program easier to understand and read. It helps to write cleaner code and maintain control over functions and modules. This approach values functionality over data. It focuses on the development of large software applications, such as C for modern operating system development. Programming languages PASCAL (introduced by Niklaus Wirth) and C (introduced by Dennis Ritchie) follow this approach.

Programming method —

This approach is also known as the top-down approach. In this approach, programs are divided into functions that perform specific tasks. This approach is primarily used for medium-sized applications. Data is global and is accessible to all functions. The fundamental disadvantage of the programming approach is that the data is insecure because the data is global and can be accessed by any function. Program control flow is achieved through function calls and GOto statements. 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. Although these languages meet the standards for well-structured programs, software, etc., they still have some problems. Their structure was inferior to what was required at the time. They seem too general and irrelevant to real-time applications.

In order to solve this kind of problem, object oriented method OOP is developed as the solution.

Object-oriented programming (OOP) approach —

The concept of OOP is basically designed to overcome the shortcomings of the above programming approach, which is not very close to real-world applications. The requirements have increased, but the usual approach is still used. This new approach brought about a revolution in programming methodology.

Object-oriented programming (OOP) is what it is, and it allows you to write 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 states and behaviors of these classes and objects are almost identical to those of the real world objects.

Let’s take a closer look at the general concepts of OOP, as follows:

What are classes and objects?

This is the basic concept of OOP; An extended concept of the structure used in C. It is an abstract, user-defined data type. It consists of several variables and functions. The primary purpose of this class is to store data and information. The members of a class define the behavior of the class. A class is a blueprint for an object, but we can say that the implementation of a class is an object. This class is not visible to the world, but objects are.

Class car
{
	int car_id;
	char colour[4];
	float engine_no;
	double distance;

	void distance_travelled();
	float petrol_used();
	char music_player();
	void display();
}
Copy the code

In this case, the class car has attributes car_id, color, engine_NO, and distance. It is similar to a real-world car with the same specifications and can be declared public (visible to everyone outside the class), protected and private (invisible to anyone). In addition, there are methods such as distance_travelled (), petrol_used (), music_player () and display (). In the code given below, the car is the class and C1 is the object of the car.

#include <iostream> using namespace std; class car { public: int car_id; double distance; void distance_travelled(); void display(int a, int b) { cout << "car id is=\t" << a << "\ndistance travelled =\t" << b + 5; }}; int main() { car c1; // Declare c1 of type car c1.car_id = 321; c1.distance = 12; c1.display(321, 12); return 0; }Copy the code

Data abstraction —

Abstract is the act of representing important features and particular features without background details or explanations of that feature. Data abstraction simplifies database design.

Physical Level:

It describes how records are stored, which are usually hidden from the user. It can be described by the phrase “storage block”.

Logical level:

It describes the data stored in the database and the relationships between the data. Programmers usually work at this level because they know the capabilities required to maintain relationships between data.

View level:

Applications hide details of data types and information for security purposes. This level is usually implemented with the help of a GUI and displays detailed information for the user.

Packaging –

Encapsulation is one of the basic concepts in object-oriented programming (OOP). It describes the idea of wrapping data and ways to process it within a unit, such as a class in Java. This concept is often used to hide the internal state representation of an object from the outside.

Inherit –

Inheritance is the ability of a class to inherit the functionality or properties of another class from its parent. When we write a class, we inherit properties from other classes. So when we create a class, we don’t have to write all the properties and functions over and over again, because they can be inherited from another class that owns it. Inheritance allows users to reuse code and reduce its redundancy where possible.

import java.io.*; class GFG { public static void main(String[] args) { System.out.println("GfG!" ); Dog dog = new Dog(); dog.name = "Bull dog"; dog.color = "Brown"; dog.bark(); dog.run(); Cat cat = new Cat(); cat.name = "Rag doll"; cat.pattern = "White and slight brownish"; cat.meow(); cat.run(); Animal animal = new Animal(); animal.name = "My favourite pets"; animal.run(); } } class Animal { String name; public void run() { System.out.println("Animal is running!" ); } } class Dog extends Animal { /// the class dog is the child and animal is the parent String color; public void bark() { System.out.println(name + " Wooh ! Wooh !" + "I am of colour " + color); } } class Cat extends Animal { String pattern; public void meow() { System.out.println(name + " Meow ! Meow !" + "I am of colour " + pattern); }}Copy the code

Polymorphism –

Polymorphism refers to the ability to process data in multiple forms. It allows the same task to be performed in a variety of ways. It consists of method overloading and method overwriting, that is, writing a method at once and performing many tasks using the same method name.

#include <iostream> using namespace std; void output(float); void output(int); void output(int, float); int main() { cout << "\nGfG! \n"; int a = 23; Float b = 2.3; output(a); output(b); output(a, b); return 0; } void output(int var) { // same function name but different task cout << "Integer number:\t" << var << endl; } void output(float var) { // same function name but different task cout << "Float number:\t" << var << endl; } void output(int var1, float var2) { // same function name but different task cout << "Integer number:\t" << var1; cout << " and float number:" << var2; }Copy the code

Some important things to know about OOP:

OOP treats data as a key element.

The focus is on the data, not the program.

Break the problem down into simpler modules.

Data is not allowed to flow freely throughout the system, i.e., local control flow.

Data is protected by external functions.

The advantages of OOP —

It mimics the real world very well.

With OOP, programs are easy to understand and maintain.

OOP provides code reuse. Classes that have been created can be reused without having to write them again.

OOP facilitates rapid development of programs that can develop classes in parallel.

With OOP, programs are easier to test, manage, and debug.

Disadvantages of OOP

When using OOP, classes are sometimes overgeneralized.

Relationships between classes sometimes become superficial.

OOP design is tricky and requires proper knowledge. In addition, OOP programming needs to be properly planned and designed.

To program with OOP, programmers need appropriate skills, such as the ability to design, program, and think in terms of objects and classes.

Article source: geeksforGeeks

Every day to learn a little knowledge, I hope to help you ~

In addition, if you want to improve your programming ability, learn C language C++ programming! Overtake on the curve, one step faster! The author here may be able to help you ~

C language C++ programming learning exchange circle, QQ group [****951258402] wechat public number: C language programming learning base

Share (source code, project actual combat video, project notes, basic introduction tutorial)

Welcome to change careers and learn programming partners, use more information to learn and grow faster than their own thinking oh!

Programming learning video sharing: