MCPcopy Create free account
hub / github.com/ActiveState/code / main

Function main

recipes/Python/578484_Observer_Pattern/recipe-578484.py:52–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50
51# Example
52def main():
53 print "Creating data1 without notification for attrs name & surname"
54 data1 = Data(excluded=['name','surname'])
55 print "Creating data2 without notification for attr age"
56 data2 = Data(excluded=['age'])
57
58 obs1 = Observer1()
59 data1.attach(obs1)
60 data1.attach(obs1)
61
62 obs2 = Observer2()
63 data2.attach(obs2)
64 data2.attach(obs2)
65
66# now try it
67# you can set any attribute directly
68 print "Setting data1.name=Heather - Notification unnecessary"
69 data1.name = 'Heather'
70 print "Setting data1.num=333 - Notification expected"
71 data1.num = 333;
72
73 print "Setting data2.name=Molly - Notification expected"
74 data2.name = 'Molly'
75 print "Setting data2.age=28 - Notification unnecessary"
76 data2.age = 28
77 print "Setting data2.eyecolor=blue - Notification expected"
78 data2.eyecolor='blue';
79
80if __name__ == '__main__':
81 main()

Callers 1

recipe-578484.pyFile · 0.70

Calls 4

Observer1Class · 0.85
Observer2Class · 0.85
DataClass · 0.70
attachMethod · 0.45

Tested by

no test coverage detected