C# | OOP Principles | Simplified
--
Object Oriented Programming, is a paradigm of programing in which a program is built around objects in which they communicate/depend/ extend each other.
OOP is the paradigm that is mostly used in the industry and any programmer in this day and age is practicing the design.
The most popular way OOP is implemented by class based structure, where classes are representations of Entities in the real world
(Car, Person, Location etc..)
None the less, there are sets of principles/guidelines that good to keep in mind to have a healthy usage of this programming paradigm.
— Principles of Object-Oriented Programming
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
1-Encapsulation
Encapsulation is the practice of hiding/concealing the internal implementation of a class that should not be exposed throughout the program but needed to be referenced in the class internal implementation, this practice offers less volatility to the class properties and in exchange methods can be used to interface with the class.
- Example
In here, have a Person class that has couple of public Properties and private ID, since ID is a sensitive part of Person Information, we set it as private and have a public property that retrieves the ID with a masked value using MaskID method. this way we do not expose the actual value of the ID and we can easily change the representation of ID if when it’s retrieved.
2-Abstraction
Abstraction is an extension of encapsulation. It means providing only the necessary information to the outside world while hiding the internal details of implementation. It reveals only the appropriate operations for other objects. The advantage of this is that we can change the implementation without affecting the class, as…