What Are the 4 Fundamental Characteristics in C# OOP?

Stanislava Stoeva
2 min readNov 15, 2021

--

Basic Fundamentals of Object-Oriented Programming

Objected-Oriented Programming got 4 characteristics to know as pillars in OOP. In this article, I will discuss each of them in detail.

Inheritance

Inheritance is an essential part of object-oriented programming. Classes can inherit from each other, which means inheriting class can get all the inherited class’s behaviour, also known as a base class.

The example below says that Citizen: Person, which means class Citizen is inheriting a Class Person.

Figure 1: Screenshot created by the author

So to complete creating a citizen in this example, you add params name and age in the new Citizen. That is possible because you got the properties of class Person. After all, it is the base class inherited by the Citizen class known as a child. Also, you are allowed to extend or override the behaviour. That could happen when if the base class you create a virtual class that is overridden in the child class by changing its behaviour.

Figure 2: Screenshot created by the author

Encapsulation

Encapsulation is a process that helps you to hide the internal working process of your class. That means you can use specification that needs to be public, used by consumers of your class, while the work of that class is hidden. The advantage is that a class’s work can change how it works without changing its consumers.
In C#, there are access modifiers that enable you to control code visibility:

  • private: only visible to the containing class
  • protected: only visible to the containing class and inheritors
  • internal: only visible to classes in the same assembly
  • public: visible to everyone
  • sealed: doesn’t allow inhabitation to other classes

Also, I should mention that classes could be private, which are only visible to contain class.

Abstraction

Abstraction is a process to hide internal details and show only functionality. The abstract modifier indicates the incomplete implementation, and the keyword abstract is used to declare class or methods as abstract.

Polymorphism

Polymorphism comes from the Greek word, which means one object has many forms or one name with multiple functionalities. “Poly” means many, and “morph” means forms. Polymorphism provides the ability for a class to have multiple implementations with the same name.

Have a nice day!

~ Stasi

--

--

Stanislava Stoeva

Junior Web Developer 💻 Interested in Web and Front-End