Object-Oriented Programming

Various Programming Paradigms

Procedural Programming

  • It is highly structured
  • It makes it easy to keep a track of program flow
  • It is quite simple and easy to implement
  • Procedural programming is susceptible to design changes
struct employer {
int empid;
char name[100];
char post;
}
void reademployee(employer e1){
cout<<"Enter id";
cin>>e1.empid;
cout<<"Enter Name";
gets(e1.name);
cout<<"Enter post";
cin>>e1.post;
}
struct employer {
int empid;
char name[100];
char post;
int empno;
}
  • Also, procedural programming leads to increased time and cost overheads during design changes.

Object-Oriented Programming

  • Object-based programming localizes the implementation details
class employer {
int empid;
char name[100];
char post;
int empno;
public:
void reademployee();
void removeemployee();
}
class employer {
int empid;
char name[100];
char post;
int empno;
int salary;
public:
void reademployee();
void removeemployee();
}
  • OOP overcomes most shortcoming and drawbacks of POP
  • OOP supports user-defined types
  • OOP implements information hiding and abstraction, etc.

Basic concepts of OOP

  • Data Abstraction
  • Data Encapsulation
  • Modularity
  • Inheritance
  • Polymorphism

Objects:-

Class:-

  • Data Abstraction:-
  • Encapsulation:-
  • Modularity:-
  1. It reduces the complexity to some extent
  2. It creates a number of well-defined boundaries within the program
  • Inheritance:-
  • Polymorphism:-
#include <iostream>using namespace std;class Employer{
private: //Data abstraction,Encapsulation, Data Hiding
int empid=1234432;
int empno=1;
string empname="Abhishek";
public:
void details(){
cout<<"Name:"<<empname<<"\n";
cout<<"ID:"<<empid<<"\n";
cout<<"Employer No:"<<empno<<"\n";
}
};
class SubEmployer:Employer{ //Inheritance
private:
int empid1=12342232;
int empno1=2;
string empname1="Trideep";
public:
void detailsFinal(){
details();
cout<<"Name:"<<empname1<<"\n";
cout<<"ID:"<<empid1<<"\n";
cout<<"Employer No:"<<empno1;
}
void poly(int x){ //Polymorphism using function overloading
cout<<"Used function poly in one way:"<<x<<"\n";
}
void poly(double x){
cout<<"Used function poly in another way:"<<x<<"\n";
}
void poly(string x){
cout<<"Used function poly in yet another way:"<<x<<"\n";
}
};
int main() //Driver Function
{
SubEmployer emp;
emp.detailsFinal();
cout<<"Illustrated Polymorphism using Function overloading"<<"\n";
emp.poly(6);
emp.poly(7.8);
emp.poly("Polymorphism");
return 0;
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why I Love AWS Lambda (and Think Serverless is the Future)

Important Hadoop commands

4k~怪胎 ~”I WeirDo″~!完整版本!~(HD-2020)手表

The 8 best low-code development platforms for software vendors

Deploying a MERN stack application in Azure VM

InsureDao Testnet

{UPDATE} Super Mini Ninja for ms free game Hack Free Resources Generator

Why Deleted Files Can Be Recovered?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Kumar

Abhishek Kumar

More from Medium

How to Become a Backend Developer in 2022

Python object-oriented programming — Composition over Inheritance

Polymorphism in Object Oriented Programming

4 Pillars of OOP: Object Oriented Programming