encapsulation example 1
This commit is contained in:
parent
2a2ed48501
commit
ee4300f2e4
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 New Issue
Block a user