- What is Encapsulation?
- What is Abstraction?
- What is the functionality of Encapsulation and Abstraction in C#?
Encapsulation and abstraction is an essential part of C sharp programming that is mostly used for hiding complex code from the unauthorized user and shows only relevant information.
What is encapsulation?
Encapsulation is the process of hiding irrelevant data from the user. To understand encapsulation, consider an example of a mobile phone. Whenever you buy a mobile, you don’t see how circuit board works. You are also not interested to know how digital signal converts into the analog signal and vice versa. These are the irrelevant information for the mobile user, that’s why it is encapsulated inside a cabinet.
In C# programming, we will do the same thing. We will create a cabinet and keep all the irrelevant information in it that will be unavailable to the user.
What is abstraction?
Abstraction is just opposite of Encapsulation. Abstraction is a mechanism to show only relevant data to the user. Consider the same mobile example again. Whenever you buy a mobile phone, you see their different types of functionalities as a camera, mp3 player, calling function, recording function, multimedia etc. It is an abstraction because you are seeing only relevant information instead of their internal engineering.
Summary
In this chapter you learned what is Encapsulation and Abstraction in C#. In next chapter, you will learn various types of access specifiers that are used to encapsulate code.