Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce78460

Browse files
authored
Update Incapsulation
1 parent 2e5ea1e commit ce78460

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

OOP/Incapsulation

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,27 @@ obj = Myobject()
3535
#obj.__private_value = 200 # Tak k private atributu obratitsya nelzya. Nado cherez metod setter
3636
obj.set_value(200)
3737
print(obj.get_value()) # 200
38+
39+
40+
################################# 3) Svoistva objekta. Trebuetsya podderzhka yazyka. Bolee predpochtitelen.
41+
42+
class Myobject:
43+
44+
def __init__(self):
45+
self.__atribute = 0
46+
47+
@property
48+
def atribute(self):
49+
return self.__atribute
50+
51+
@atribute.setter # @atribute - takoe zhe kak i imya metoda v gettere
52+
def atribute(self, value):
53+
if value < 500:
54+
self.__atribute = value
55+
56+
57+
obj = Myobject()
58+
print(obj.atribute) # 0
59+
60+
obj.atribute = 200 # 200
61+
print(obj.atribute)

0 commit comments

Comments
 (0)