So we have reached to a point where you guys need to know the three principles of object oriented programming. These are Encapsulation, Polymorphism and Inheritance and also called (PIE). In this post I’m going to give some little description about these three principles. I’ll provide more details about them with coding examples in later posts.
Using encapsulation in our code we can keep safe our code and data from outside interference and misuse. This is the most important principle of all. We can prevent ourselves from introducing a bug in our program by encapsulating our code.
In short polymorphism means many forms of a single object. For very simple example, recall the fact that Carbon (a chemical element) has two well-known polymorphs - Diamond and Graphite. Both are Carbon but the behaviors are different due to the internal structures. C# and other Object oriented language supports polymorphism by changing the behavior of and object at run-time.
Inheritance is a process by which an object acquires the properties of another object. For example, Lamborghini and Bugatti are two car companies. Both are capable of designing and selling racing cars. But they didn't invent the definition of car. To be more precise, we all know that a car has 4 wheels, runs on fuel, has a steering wheel etc. We can tell with our eyes closed by listening to these properties that this thing is a car. So a racing car designed by Lamborghini and Bugatti to be a car, should inherit the property of a basic car (i.e. it should have 4 wheels, should run on fuel etc.).