mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 23:12:24 +03:00
about private and protected scope in python
This commit is contained in:
23
OOP/wiki.txt
23
OOP/wiki.txt
@@ -51,16 +51,20 @@
|
|||||||
keyword which acts like a this pointer
|
keyword which acts like a this pointer
|
||||||
but in @staticmethod we can't do that.
|
but in @staticmethod we can't do that.
|
||||||
|
|
||||||
-> private variable:
|
-> protected variable and function:
|
||||||
|
|
||||||
python doesn't provide any means to limit the access of data members
|
python doesn't provide any means to limit the access of data members
|
||||||
of class. The only thing smart is to use convention.
|
of class. The only thing smart is to use convention.
|
||||||
|
|
||||||
Any variable with underscore means it's a private variable and
|
Any variable with underscore means it's a protected variable and
|
||||||
don't modify it.
|
don't modify it.
|
||||||
|
|
||||||
|
Same goes for function in a class (methods).
|
||||||
|
|
||||||
For ex:
|
For ex:
|
||||||
_name is private variable in a class.
|
_name is protected variable in a class.
|
||||||
|
|
||||||
|
_getName() is protected function in a class.
|
||||||
|
|
||||||
|
|
||||||
-> Inheritance:
|
-> Inheritance:
|
||||||
@@ -155,3 +159,16 @@
|
|||||||
MRO allow us to determine the order in which
|
MRO allow us to determine the order in which
|
||||||
the Inheritance need to be processed. This
|
the Inheritance need to be processed. This
|
||||||
order is determined using Depth first search.
|
order is determined using Depth first search.
|
||||||
|
|
||||||
|
|
||||||
|
-> private variable and function:
|
||||||
|
|
||||||
|
Any variable with double underscore means it's a protected variable and
|
||||||
|
don't modify it.
|
||||||
|
|
||||||
|
Same goes for function in a class (methods).
|
||||||
|
|
||||||
|
For ex:
|
||||||
|
__name is protected variable in a class.
|
||||||
|
|
||||||
|
__modifyName() is protected function in a class.
|
||||||
|
|||||||
Reference in New Issue
Block a user