What is OOPS (object oriented programming) in C# ?

Object Oriented Programming Language.

Object oriented programing (OOP) is a programming paradigm which is based on Objects. They may contain data in the form of fields and methods (procedures). Objects are usually instances of Classes, which are used to interact with each other therefore gaining reusability and modularity.

In OOP we have certain concepts like:
Classes, Objects, Abstraction, Encapsulation, Inheritance, Polymorphism

We’ll look them one by one.

First of all let us start with Class.

Class

A Class is a template or a blueprint of an object. It contains data members and member functions. They define the format of data and procedures (functions) an object is going to have.

In the real world you can think – human, automobile, birds as a class.
You can say that a class is a user defined data type.
Public class student
{
…….
}




Object:

Objects are the instances of Classes. They are the basic components that perform actions furthermore they know how to interact with other programs.

Example:

Objects example
We can create an object of a class like:
Student stu = new Student();
Here Student is the class and stu is the object.

OOPS has 4 important concepts or you can say they are the pillars of OOP. They are Abstraction, Encapsulation, Inheritance, Polymorphism.

Abstraction:

Basically it is an act of representing only the necessary and essential features to the outside world. It relies on separation of interface and implementation. We use abstraction in programming language using Interfaces and Abstract Classes.

Encapsulation:

If you search on google, you will find that encapsulate means to enclose (something). So here Encapsulation means encapsulating data to a single unit.

Let us take a real time example. You must have seen a capsule, what is it, it is just a wrapper of medicine. So what exactly a capsule is doing, one it is protecting medicine, 2nd it is reducing complexity right.
Hence we can conclude from the example that encapsulation is doing 2 things basically:

  • Wrapping up of data to a single unit
  • Reducing complexity