In this article I am going to discuss about C# Object-Oriented Programming (OOP) but before that if you had not read my previous article of C# command line arguments then must read it. In programming two types of programming structured are mostly used. One is procedural programming and other one is object oriented programming. Procedural programming is all about writing methods or functions that perform operations on data and second one is object-oriented programming which is about creating objects that contain the definition of data and methods.

Introduction to C# Object-Oriented Programming (OOP)

Object-Oriented Programming is not any programming language like C#, C++ or so on. It is a technique or principal that provide a programming structure or principles for developing an application or software. In simple words it is called methodology. Like object-oriented programming methodology there are some other methodlogies are exists like procedural programming , structured programming and so on. But to develop and fast and scalable application object-oriented programming is used mostly. There are some languages which does not support object-oriented programming like C language. But also there are some languages which support object-oriented programming like C++, Java and C#. Luckily in C# we can use the object-oriented programming to develop an application.

Why Object-Oriented Programming (OOP)?

As we already discussed there are other techniques or structures are also there like procedural programming, modular programming and so on. So why we use object-oriented programming structure? This type of question is always arises when you are new to object-oriented programming. So don’t worry you will get the answer shortly. But before that lets talk about procedural programming. In procedural programming we create different-2 functions to handle different-2 operations. For example you are developing one calculator then what should you do is you will create different methods for operations like addition, subtraction, multiplication , divison and so on. You can use these functions by passing parameters or not. Its upto you.

But in object-oriented programming you will be creating all this functions inside one class and then you can use this member functions using creating their instances.

Problems in Procedural or Modular Programming

  • Redundancy
  • Not Extensible
  • Complexity
  • Not Maintainable

1. Redundancy: In this type of programming there is no reusability of code therefore we have to write whole code again and again which leads to code redundancy.

2. Not Extensible : We cannot extend the feature of procedural or modular programming because it is limited to its scope. We cannot use the feature of one function into another.

3. Complexity: As there is code redundancy therefore it is difficult to understand the logic behind the code.

4. Not Maintainable: Modular programming codes is very difficult to maintain because it involves lots of functions.

Advantages of Object-Oriented Programming (OOP)

C# Object-Oriented Programming Advantages

1. Code Reusability : Object-Oriented Programming allow us to use the already written code instead of writing the whole code again. In Object-Oriented Programming inheritance used for code reusability and avoid code duplication.

2. Extensible : We can extend the feature in object-oriented programming using classes and object. If we want to extend the feature of one class to another then we can do this using inheriting one class to another. This will make our program extensible.

3. Maintenance : Like procedural programming it not depend on functions to perform operations therefore it is easy to maintain our code.

4. Developing Complex Software : Object-Oriented Programming is used to develop complex applications and software that is difficult to manage with procedural and other programming techniques. Because with object-oriented programming principles we can develop complex software very easily and maintain the application code. It also helps in problem solving with its 4 pillars of Object-Oriented Programming.

5. Loose Coupling : With Object-Oriented Programming we avoid loose coupling. When one data is dependent on any data’s result then it is called tight coupling and in programming we must have to avoid tight coupling for better results.

6. Data Hiding : Data hiding or data abstraction is one of the four pillars of object-oriented programming that allow us to show only required data to user. Means if some part of code is private and we not want to show this to outside world then we can use the data abstraction one of the feature of object-oriented programming.

7. Security : As object-oriented programming provides the functionality of data hiding and encapsulation therefore it is more secured than other programming techniques and also it is very easy to troubleshoot the object-oriented programming language.

C# Object-Oriented Programming (OOP) Concepts

In C#, or other programming languages object-oriented programming (OOP) concepts are also known as pillars of object-oriented programming languages. Sometimes it is also called object-oriented principles. There are mainly 4 principles in C# Object-Oriented Programming.

  1. Encapsulation
  2. Inheritance
  3. Polymorphism
  4. Data Abstraction

Conclusion

In this C# tutorials, articles I have discussed about the C# Object-Oriented Programming in detail. Hope you found this article helpful and like this article. In my next article I am going to discuss about the four pillars of principles of object-oriented programming in detail.