Advertisement
D10d3

oop_cheatsheet-general.py

Jan 24th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import os
  2. os.system('cls')
  3.  
  4. class other_class(object):
  5. #An individual object class
  6. #note, this is instantiated under general_instance.__init__()
  7. def implicit(self):
  8. print " other_class.implicit()"
  9. def altered(self):
  10. print " other_class.altered()"
  11.  
  12. class general_class(object): #An individual object that calls another_class object
  13. def __init__(self): #instantiates and includes other_class() as 'self.other'
  14. self.other_class = other_class()
  15. def method(self):
  16. print " general_class method()"
  17. print " #general_class has a 'method()' that does not relate to other_class()"
  18. def implicit(self):
  19. print " self.other_class.implicit()"
  20. print " #general_class.implicit() hands off call to other_class.implicit() via 'self.other'"
  21. print " #this results in:"
  22. self.other_class.implicit()
  23. def altered(self):
  24. print " general_class.altered()"
  25. print " #general_class has an altered()"
  26. print " self.other_class.altered()"
  27. print " #general_class calls other_class.altered() via 'self.other'"
  28. self.other_class.altered()
  29. print " general_class.altered()"
  30. print " #general_class.altered() continues after 'self.other' call"
  31.  
  32. class display(object):
  33. def general_instance(self):
  34. print "display general_instance()of general_class() calls:"
  35. print ""
  36. print "general_class initializes it's settings with an '___init___' method"
  37. print" def __init__(self):"
  38. print" self.other_class = other_class()"
  39. print" #instantiates and includes other_class() as 'self.other'"
  40. print ""
  41. print "'general_instance.method()' results in:"
  42. general_instance.method()
  43. print""
  44. print "'general_instance.implicit()' results in:"
  45. general_instance.implicit()
  46. print " #unlike a parent/child, other_class methods cannot be called unless general_class has a method to hand off the call"
  47. print""
  48. print "'general_instance.altered()' results in:"
  49. general_instance.altered()
  50. print""
  51.  
  52.  
  53. general_instance = general_class()
  54. show = display()
  55.  
  56. show.general_instance()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement