Why do we need classes?
Definition and overview of classes in programming
Classes are useful in various ways. As we have seen in this tutorial so far, it is very easy to use the controls and their properties in our page. This is because the properties and functions of these controls are already coded in various classes of the .NET Framework. All we need to know is what these properties are and how to use them in our applications. We do not need to know the exact code that makes the controls work. This is known as encapsulation in object-oriented programming. Once a class has been defined and tested, developers can use it in their applications without knowing the code behind it.
Another advantage of using classes is that we can extend them. Let us understand this with an example. We have created a class named `Person'. The class has properties like name, age and gender. Sometime later, we need another class- `student'. This class should have the properties such as name, age, gender, grade and stream. Notice that some properties of the class `student' are the same as in the `Person' class. We can define the `student' class from scratch but why should we write everything again? We can inherit the `student' class from the `Person' class. This will pass onto the properties of the `Person' class to the `student' class. We just need to add the extra properties in the `student' class. In fact, we can extend the `Person' class in other situations too. An `employee' class or a `teacher' class can be created based on the `Person' class. This is a main feature of object-oriented programming and is known as Inheritance. A class can be extended to create other classes. This saves a lot of coding time for the developers as they don't have to write everything from the beginning. "Why re-invent the wheel?" is the phrase used by object-oriented gurus.