Data Hiding in PythonWhat is Data Hiding?Data hiding is a part of object-oriented programming, which is generally used to hide the data information from the user. It includes internal object details such as data members, internal working. It maintained the data integrity and restricted access to the class member. The main working of data hiding is that it combines the data and functions into a single unit to conceal data within a class. We cannot directly access the data from outside the class. This process is also known as the data encapsulation. It is done by hiding the working information to user. In the process, we declare class members as private so that no other class can access these data members. It is accessible only within the class. Data Hiding in PythonPython is the most popular programming language as it applies in every technical domain and has a straightforward syntax and vast libraries. In the official Python documentation, Data hiding isolates the client from a part of program implementation. Some of the essential members must be hidden from the user. Programs or modules only reflected how we could use them, but users cannot be familiar with how the application works. Thus it provides security and avoiding dependency as well. We can perform data hiding in Python using the __ double underscore before prefix. This makes the class members private and inaccessible to the other classes. Let's understand the following example. Example - Output: 1 2 Traceback (most recent call last): File "<string>", line 17, in <module> AttributeError: 'CounterClass' object has no attribute '__privateCount' However we can access the private member using the class name. Output: 1 2 2 Advantages of Data HidingBelow are the main advantages of the data hiding.
Disadvantages of Data HidingEvery coin has two sides if there are advantages then there will be disadvantage as well. Here are the some disadvantages are given below.
ConclusionData hiding is an important aspect when it comes to privacy and security to particularly within the application. It plays an essential role in preventing unauthorized access. It has some disadvantages, but these are avoidable in front of its advantages. |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India