OOP is a design philosophy. It stands for Object Oriented Programming. Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages (C, Pascal, etc.). Everything in OOP is grouped as self sustainable “objects”. Hence, you gain reusability by means of four main object-oriented programming concepts.
In order to clearly understand the object orientation model, let’s take your “hand” as an example. The “hand” is a class. Your body has two objects of the type “hand”, named “left hand” and “right hand”. Their main functions are controlled or managed by a set of electrical signals sent through your shoulders (through an interface). So the shoulder is an interface that your body uses to interact with your hands. The hand is a well-architected class. The hand is being reused to create the left hand and the right hand by slightly changing the properties of it.
What is an Object?
An object can be considered a “thing” that can perform a set of related activities. The set of activities that the object performs defines the object’s behaviour. For example, the Hand (object) can grip something, or a Student (object) can give their name or address.
In pure Oop terms an object is an instance of a class.
What is a Class?
A class is simply a representation of a type of object. It is the blueprint, or plan, or template, that describes the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.
public class Student
{
}
How to identify and design a Class?
This is an art; each designer uses different techniques to identify classes. However according to Object Oriented Design Principles, there are five principles that you must follow when design a class,
SRP – The Single Responsibility Principle –
A class should have one, and only one, reason to change.
OCP – The Open Closed Principle –
Should be able to extend any classes’ behaviors, without modifying the classes..
LSP – The Liskov Substitution Principle-
Derived classes must be substitutable for their base classes.
DIP – The Dependency Inversion Principle-
Depend on abstractions, not on concretions.
ISP – The Interface Segregation Principle-
Make fine grained interfaces that are client specific.
For more information on design principles, please refer to Object Mentor.
Additionally to identify a class correctly, you need to identify the full list of leaf-level functions or operations of the system (granular level use cases of the system). Then you can proceed to group each function to form classes (classes will group same types of functions or operations). However a well-defined class must be a meaningful grouping of a set of functions and should support the reusability, while increasing expandability or maintainability, of the overall system.
What is Encapsulation?
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In a different way, encapsulation is a protective shield that prevents the data from being accessed by the code outside this shield.
Technically in encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of own class in which they are declared.
As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.
Encapsulation can be achieved by: Declaring all the variables in the class as private and using C# Properties in the class to set and get the values of variables.


Advantages of Encapsulation:
Data Hiding: The user will have no idea about the inner implementation of the class. It will not be visible to the user that how the class is stored values in the variables. He only knows that we are passing the values to accessors and variables are getting initialized to that value.
Increased Flexibility: We can make the variables of the class as read-only or write-only depending on our requirement. If we wish to make the variables as read-only then we have to only use Get Accessor in the code. If we wish to make the variables as write-only then we have to only use Set Accessor.
Reusability: Encapsulation also improves the re-usability and easy to change with new requirements.
Testing code is easy: Encapsulated code is easy to test for unit testing.
What is an Abstract class?
Abstraction is selecting data from a larger pool to show only the relevant details to the object. It helps to reduce programming complexity and effort.
Let’s Study Abstraction concept with an Example
Suppose you want to create a banking application and you are asked to collect all the information about your customer. There are chances that you will come up with following information about the customer

But, not all of the above information is required to create a banking application.
So, you need to select only the useful information for your banking application from that pool. Data like name, address, tax information, etc. make sense for a banking application

Since we have fetched/removed/selected the customer information from a larger pool, the process is referred as Abstraction.

Abstract Class
A class which is declared “abstract” is called as an abstract class. It can have abstract methods as well as concrete methods. A normal class cannot have abstract methods.
Abstract Method
A method without a body is known as an Abstract Method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods.
Rules of Abstract Method
Abstract methods do not have an implementation; it only has method signature
If a class is using an abstract method they must be declared abstract. The opposite cannot be true. This means that an abstract class does not necessarily have an abstract method.
If a regular class extends an abstract class, then that class must implement all the abstract methods of the abstract parent.
Difference between Abstraction and Encapsulation
Abstraction Encapsulation
Abstraction solves the issues at the design level. Encapsulation solves it implementation level.
Abstraction is about hiding unwanted details while showing most essential information. Encapsulation means binding the code and data into a single unit.
Abstraction allows focussing on what the information object must contain Encapsulation means hiding the internal details or mechanics of how an object does something for security reasons.
Difference between Abstract Class and Interface
Abstract Class Interface
An abstract class can have both abstract and non-abstract methods.
The interface can have only abstract methods.
It does not support multiple inheritances.
It supports multiple inheritances.
It can provide the implementation of the interface.
It can not provide the implementation of the abstract class.
An abstract class can have protected and abstract public methods.
An interface can have only have public abstract methods.
An abstract class can have final, static, or static final variable with any access specifier.
The interface can only have a public static final variable.
Advantages of Abstraction
The main benefit of using an abstract class is that it allows you to group several related classes as siblings.
Abstraction helps to reduce the complexity of the design and implementation process of software.
When to use Abstract Methods & Abstract Class?
Abstract methods are mostly declared where two or more subclasses are also doing the same thing in different ways through different implementations. It also extends the same Abstract class and offers different implementations of the abstract methods.
Abstract classes help to describe generic types of behaviors and object-oriented programming class hierarchy. It also describes subclasses to offer implementation details of the abstract class.
In c#, Inheritance is a one of the primary concept of object oriented programming (OOP) and it is used to inherit the properties from one class (base) to another (child) class.
The inheritance will enable us to create a new class by inheriting the properties from other classes to reuse, extend and modify the behaviour of other class members based on our requirements.
In c# inheritance, the class whose members are inherited is called a base (parent) class and the class that inherits the members of base (parent) class is called a derived (child) class.
C# Inheritance Syntax


C# Inheritance Example

Multi level Inheritance
Generally, c# supports only single inheritance that means a class can only inherit from one base class. However, in c# the inheritance is transitive and it allows you to define a hierarchical inheritance for a set of types and it is called a multi-level inheritance.
For example, suppose if class C is derived from class B, and class B is derived from class A, then the class C inherits the members declared in both class B and class A.

If you observe above code snippet, the class C is derived from class B, and class B is derived from class A, then the class C inherits the members declared in both class B and class A. This is how we can implement multi-level inheritance in our applications.
C# Multi Level Inheritance Example
Following is the example of implementing multi-level inheritance in c# programming language.

If you observe above example, we implemented a three classes (A, B, C) and the class C is derived from class B, and class B is derived from class A.
By implementing a multi-level inheritance, the class C can inherits the members declared in both class B and class A.
When we execute above c# program, we will get the result like as shown below.
C# Multiple Inheritance
As discussed, c# supports only single inheritance that means a class can only inherit from one base class. In case, if we try to inherit a class from multiple base classes, then we will get a compile time errors.
For example, if class C is trying to inherit from Class A and B at the same time, then we will get a compile time error because multiple inheritance is not allowed in c#.

What is Polymorphism?
Polymorphism means providing an ability to take more than one form and it’s a one of the main pillar concept of object oriented programming, after encapsulation and inheritance. Generally, the polymorphism is a combination of two words, one is poly and another one is morphs. Here poly means “multiple” and morphs means “forms” so polymorphism means many forms. In c#, polymorphism provides an ability for the classes to implement a different methods that are called through the same name and it also provides an ability to invoke the methods of derived class through base class reference during runtime based on our requirements. In c#, we have a two different kind of polymorphisms available, those are 1. Compile Time Polymorphism 2. Run Time Polymorphism.
Compile Time Polymorphism
In c#, Compile Time Polymorphism means defining a multiple methods with same name but with different parameters. By using compile time polymorphism, we can perform a different tasks with same method name by passing different parameters.
In c#, the compile time polymorphism can be achieved by using method overloading and it is also called as early binding or static binding.
