Understanding Object-Oriented Programming
Overview and definition of object-oriented programming.
Almost every modern day programming language uses object oriented programming concepts and C# is no exception. Many beginner developers avoid the topic because of its complex nature. However, learning object-oriented programming is not difficult at all. Once we grasp the basic concepts, programming will become a lot easier. The very purpose of object-oriented programming is to make the programs easier to create, maintain and understand.
Another reason why we want to know about object-oriented programming is that the .NET framework relies heavily on it. To make better use of the .NET framework and take advantage of all its features, it is necessary to have at least a basic understanding of object-oriented programming.
Before we proceed, note that the object-oriented programming is a detailed concept and we cannot cover everything here. In this section, we will learn the absolute essentials about object-oriented programming.
Object-oriented programming is based on the concept of objects and classes. Objects are entities with properties and methods (functions). In real life, we see many objects around us. A simple example is a car. A car has properties such as its color and model. A car also has functions like start and stop.
In object-oriented programming, we create objects to represent real life entities. Take the example of a person. A person has some properties (such as name, age and gender) and functions (such as walk, talk and eat). If we want to represent a person in a program, we can use an object.
To use an object we first need to create a class. We define the properties and functions of an object inside a class. Once the class is defined with its required properties and functions, we can create objects of the class. All the objects of a class will have the same properties and methods. Hence, we can say that a class acts like a blueprint for creating objects. For example, we can first create a person class with necessary properties and functions and then create different objects of this person class. All these objects will have the properties and functions defined in the person class although the values may differ. For example, their names, ages and genders may be different but all the objects will have these properties.