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

Building RabbitMQ Consumer With Python & Connecting Cassandra DB

Reachy now runs ROS!

Same Tree🎹

My Kotlin Diaries (Part 1) — Love at First Sight

Three Python Tips to Improve Your Workflow

Quantum Computing using Qiskit, IBM Q Experience and Python

Garmin Express not working on Windows 10

Week 1

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

Mutable, immutable…everything is an object!

The Top 5 Books to Learn Java

Object Oriented Concepts

Object-oriented programming (OOP).