-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (28 loc) · 864 Bytes
/
main.py
File metadata and controls
37 lines (28 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Helloer:
"""
Helloer is a person that say hello to the queen.
"""
def __init__(self, name="Parham"):
self.count = 0
self.name = name
def say(self) -> str:
self.count += 1
return "Hello"
class Queen:
"""
Queen must have only one person that say hello to her
"""
def __init__(self, helloer=Helloer("Parham")):
self.helloer = helloer
if __name__ == "__main__":
# here we create two differnt instance of the queen
# class but both of them are using the same initial
# value for their helloer field, do you believe this?
q1 = Queen()
print(q1.helloer.say())
print(q1.helloer.count)
q2 = Queen()
print(q2.helloer.count)
# q2 helloer never say hello but because they share
# the same instance of the helloer its conut also
# increased.