diff --git a/python-temel/encapsulation.py b/python-temel/encapsulation.py new file mode 100644 index 0000000..f6d5cc5 --- /dev/null +++ b/python-temel/encapsulation.py @@ -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! diff --git a/python-temel/encapsulation.py~ b/python-temel/encapsulation.py~ new file mode 100644 index 0000000..3cbdfd9 --- /dev/null +++ b/python-temel/encapsulation.py~ @@ -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!