Skip to content

Commit ec9c83d

Browse files
committed
Add demo for class data scalability (in class Man_from_moon)
1 parent 9971a8c commit ec9c83d

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

SimpleOOP/src/simpleoop.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,39 @@ def series(self):
2626
yield self.b
2727
self.a, self.b = self.b, self.a+self.b
2828

29-
class Mouth():
29+
class Mouth:
3030
def __init__(self):
3131
print('Constructor is called while object is defined.')
3232
def speak(self):
3333
print('Mouth can speak.')
3434
def sing(self):
3535
print('Mouth can sing.')
3636

37+
class Man_from_moon():
38+
def __init__(self, **kargs):
39+
print('This class defines the scalability of the class data.')
40+
print('Use of dictoionaries in class variable definition can make the class data scalable easily.')
41+
self.variables = kargs
42+
43+
def get_face(self):
44+
print('Getting the face of man from moon')
45+
print('This makes it with limited scalability')
46+
return self.variables.get('face', None) # default value returned for face is None
47+
48+
def set_face(self, face):
49+
print('Setting the face of man from moon')
50+
print('This makes it with limited scalability')
51+
self.variables['face'] = face
52+
53+
def get_variable(self, k):
54+
# k is the name of the varible
55+
print('using the key word variables to set and get makes it easier to deal with scalibility of class data')
56+
return self.variables.get(k, None) # default value of 'None' is returned if variable not defined
57+
58+
def set_variable(self, k, v):
59+
print('Key-value argument makes the class model easily scalable in python.')
60+
self.variables[k] = v
61+
3762
def main():
3863
# instantiate: make object of the class
3964
f = Fibonacci(0,1)
@@ -46,5 +71,16 @@ def main():
4671
my_mouth = Mouth() # my_mouth = object of the class Mouth
4772
my_mouth.speak()
4873
my_mouth.sing()
49-
74+
75+
# class data scalability discussed and demonstrated
76+
marty = Man_from_moon(face = 'MoonFace', intelligence = 'HighIntell')
77+
print('Getting face value from constructor: ', marty.get_face())
78+
marty.set_face('ManFace')
79+
print('Getting face value from Getter Method: ', marty.get_face())
80+
print('\nAddressing Scalability:')
81+
print('Getting value of \'face\' constructor:', marty.get_variable('face'))
82+
print('Getting value of \'intelligence\' set in constructor:', marty.get_variable('intelligence'))
83+
marty.set_variable('intelligence', 'VeryHighIntell')
84+
print('Getting new value of \'intelligence\':', marty.get_variable('intelligence'))
85+
5086
if __name__ == '__main__': main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy