As briefly mentioned earlier, OOP provides a modular approach to writing self-contained units of code. The concept of OOP centers around what we call the four pillars of object-oriented programming.
They are as follows:
- Abstraction
- Polymorphism
- Inheritance
- Encapsulation
The order doesn't really matter, but I always write the four pillars in this order because I use the mnemonic A PIE to remember each one. Let's discuss each of these concepts in more detail.
An abstraction describes what something should do without actually showing you how to do it. According to the Microsoft documentation:
"An abstraction is a type that describes a contract but does not provide a full implementation of the contract."
Included as examples of abstractions are abstract classes and interfaces. Examples of abstractions in the .NET Framework includeStream
, IEnumerable<T>
, and Object
. If the topic of abstraction seems a bit fuzzy now, don't worry. I will go into much more detail...