File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ # Have you heard about State in Programming Language?
4
+
5
+ # Very frequentlt this terminology is been used in Entity or Object Communication.
6
+
7
+
8
+ # Let's say we have to model a bank account with support for deposit and withdraw operations.
9
+ # One way to do that is by using global state
10
+
11
+ balance = 0 #balance variable is global of the program, if this below snippet is inside the class, we can call as class attribute.
12
+
13
+ def deposit (amount ):
14
+ global balance
15
+ balance += amount
16
+ return balance
17
+
18
+ def withdraw (amount ):
19
+ global balance
20
+ balance -= amount
21
+ return balance
22
+
23
+ sanjay = deposit (100 )
24
+ print (sanjay )
25
+
26
+ # The above example is good enough only if we want to have just a single account.
27
+
28
+ # ******Things start getting complicated if want to model multiple accounts.******
29
+
You can’t perform that action at this time.
0 commit comments