encapsulation example 1
This commit is contained in:
parent
2a2ed48501
commit
ee4300f2e4
2 changed files with 32 additions and 0 deletions
16
python-temel/encapsulation.py
Normal file
16
python-temel/encapsulation.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class Sample:
|
||||||
|
def __init__(self, a):
|
||||||
|
self._a = a
|
||||||
|
|
||||||
|
def disp(self):
|
||||||
|
print(self._a)
|
||||||
|
|
||||||
|
def __foo(self):
|
||||||
|
print('Sample.__foo')
|
||||||
|
|
||||||
|
|
||||||
|
s = Sample(10)
|
||||||
|
s.disp()
|
||||||
|
s._a = 20 # kötü teknik, _ ile başlatılan değişkenler dışarıdan kullanılmamalıdır
|
||||||
|
s._Sample__foo() #
|
||||||
|
#s.__foo() # exception!
|
16
python-temel/encapsulation.py~
Normal file
16
python-temel/encapsulation.py~
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class Sample:
|
||||||
|
def __init__(self, a):
|
||||||
|
self._a = a
|
||||||
|
|
||||||
|
def disp(self):
|
||||||
|
print(self._a)
|
||||||
|
|
||||||
|
def __foo(self):
|
||||||
|
print('Sample.__foo')
|
||||||
|
|
||||||
|
|
||||||
|
s = Sample(10)
|
||||||
|
s.disp()
|
||||||
|
s._a = 20 # kötü teknik, _ ile başlatılan değişkenler dışarıdan kullanılmamalıdır
|
||||||
|
s._Sample__foo() #
|
||||||
|
s.__foo() # exception!
|
Loading…
Reference in a new issue