The very first step in learning dot net is understanding the concept of Object Oriented Programming(OOP). Whenever I come across a new concept, I always question "why?? ". I realized that I appreciate them more when I understand the problems it simplifies/solves. So lets ask why??
Why??
Before OOP languages were introduced, programs were written in "structured" languages like C and Pascal. Structured languages are not modular so they are pretty long and all code written in one file.
- To debug or change such a file can be frustrating. So the problem number one is maintainability.
- If we want to use a part of code in program 1 in program 2, we need to rewrite it in program 2. This results in redundancy and problem number two: reusability is not supported.
- If we want to add a new functionality to an existing program, we might have to make changes in a number of places in the existing code making it a messy job. Problem number three: extensibility.
OOP addresses these problems. It makes programming modular and supports features like Encapsulation, Polymorphism, Inheritance and Abstraction.
Lets briefly talk about these features. At this point we will try to understand what these mean. We will know how these are supported by .NET languages when we delve into the features of C#.
Encapsulation: It is a programming mechanism that binds code and the data it manipulates together. This makes it easy to make changes to the part of code without effecting the whole program. It also helps us to provide controlled access to the data and code to outside programs. Basic unit of encapsulation in C# is class. We will discuss class in future post.
Polymorphism: It is a quality that allows a method or action to do different things in based on the context it is used in. For example, + can be used for basic addition of two numbers or for concatenating two strings.
Inheritance: This features allows for hierarchical classification. For example,
![]() |
I hope the above post has helped you to give a basic idea of OOP. I strongly encourage you to read further about the above concepts.
No comments:
Post a Comment