Object-Oriented Programming – This article will teach you the basics of Object-Oriented Programming in SQL that describes what is OOP and how to implement the OOP in SQL.
Before moving ahead, let’s know a bit about Functional Dependency
Table of Contents
Object Oriented Programming
Object Oriented Programming (OOP) is a type of programming based on real-life entities such as data members, functions, classes, and objects. It aims to bind data and function work on these data sets into a single entity to restrict their usage.
Some basic concepts of object-oriented programming are −
A Class is a blueprint of object-oriented programming and user-defined data type. It contains objects, variables, and functions. A class doesn’t have to allocate the memory location unless an object is created inside it. When a function is defined under the Class, it is called a method.
Some important properties of the class are −
- Class is a user-defined data type.
- A class contains members like data members and member functions.
- Data members are variables of the Class.
- Member functions are the methods that are used to manipulate data members.
- Data members define the properties of the Class, whereas the member functions define the Class’s behavior.
- A class can have multiple objects with properties and behavior that are common for all.
An object is a part of a class defined under the class. It is based on entities with characteristics and behavior used in object-oriented programming. An object is allocated the memory at the moment it is created.
One of the properties of OOPs is binding together the data and related functions into a single container.
Let’s think of it with a real-life example:
Let’s assume that there is a department in the hospital having two types of patients. The first one is who Covid has, and another one is who is quarantined with some symptoms of Covid.
Let’s think of the department as a Class that encapsulates the data about that department’s patients and patients treated as data members. Encapsulation is where both kinds of patients are stored in a department (Class).
Due to the concept of Encapsulation under the OOP, another feature is allowed: Encapsulation shows only the necessary information required to display.
The name defines Polymorphism as having multiple forms, which means it is the ability to perform a task in various forms. The method’s behavior depends on the type or situation in which the method is carried out.
Let’s take a look at an example of real life:
Think a person has to travel from destination A to B.
*If the person is a tourist guide, he will take the shortest path to reach the destination (B).
*If the person has a vast knowledge of the area, he may take shortcuts to reach the destination (B).
*If the person has no knowledge and is about to visit the destination for the first time, he might go for a long time.
How that person’s behavior would depend on the situation of being a tourist guide, knowledgeable person, and novice person.
Let’s consider another example:
A woman can have more than one behavior depending on the situation, like wife, mother, daughter, manager, teacher, CEO, etc. This is where the concept of polymorphism came from.
Inheritance is the process of inheriting the properties & features of another class. It is one of the main properties of OOPs, and it allows us to reusability, i.e., using a method of a class defined in another class by using inheritance.
The class that derives the properties of another class is called the child class or subclass, and the class from which the properties are inherited is the base or parent class.
Several types of inheritance are
- single inheritance
- multiple inheritances
- multi-level inheritance
- Hierarchical inheritance
- hybrid inheritance
Abstraction is the process of showing only the relevant & necessary information to the user, and the rest is hidden. Abstraction is also known as the process of hiding data.
In other words, It is the process of hiding the initial procedures from the user.
Let’s take an example:
A person who is making a payment via net banking needs to enter the required details that he has been asked to enter on the payment detail page, and the rest of the whole process of making the payment successfully is hidden. So, how payment is made behind the scenes is not shown to the final user and indicates that the payment is completed successfully.
Another example is when we ride a bike, we only know that pressing the brake will stop the cycle and rotating the throttle will accelerate, but we don’t see how it works, and we also do not think we should know that’s why this is done from the concept data abstraction.
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.