Discover more from Daily Dose of Data Science
Why Python Does Not Offer True OOP Encapsulation
Using access modifiers (public, protected, and private) is fundamental to encapsulation in OOP. Yet, Python, in some way, fails to deliver true encapsulation.
By definition, a public member is accessible everywhere. A private member can only be accessed inside the base class. A protected member is accessible inside the base class and child class(es).
But, with Python, there are no such strict enforcements.
Thus, protected members behave exactly like public members. What's more, private members can be accessed outside the class using name mangling.
As a programmer, remember that encapsulation in Python mainly relies on conventions. Thus, it is the responsibility of the programmer to follow them.
Share this post on LinkedIn: Post Link.
Find the code for my tips here: GitHub.