rksk16it

Multiple Inheritance 2

Nov 22nd, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. # ---------------------------------
  2. # Assume methods starting with underscore
  3. # to be private. They are not mentioned
  4. # in public API documentation
  5.  
  6. _totalPopulation = 0
  7.  
  8. class C1 :
  9.  
  10.     def __init__ (self) :
  11.         global _totalPopulation
  12.         _totalPopulation += 1
  13.     #
  14.  
  15.     def say (self) :
  16.         print ("C1: hello")
  17.     #
  18.  
  19.     def _c1OnlySay (self) :
  20.         print ("C1 says hi")
  21.     #
  22.  
  23.     def _myName (self) :
  24.         return "C1"
  25.     #
  26. #
  27.  
  28. class C2 :
  29.     def __init__ (self) :
  30.         global _totalPopulation
  31.         _totalPopulation += 1
  32.     #
  33.  
  34.     def say (self) :
  35.         print ("C2: hello")
  36.     #
  37.  
  38.     def _c2OnlySay (self) :
  39.         print ("C2 says hello")
  40.     #
  41.  
  42.     def _myName (self) :
  43.         return "C2"
  44. #
  45.  
  46. def talk (obj) :
  47.     obj.say ()
  48. #
  49.  
  50. def c1TalksToC2 (c1Obj, c2Obj) :
  51.     c1Obj.say ()
  52.     c2Obj.say ()
  53.     c1Obj._c1OnlySay ()
  54.     c2Obj._c2OnlySay ()
  55. #
  56.  
  57. def totalPopulationOfC1AndC2 () :
  58.     print ("Total Population of C1 and C2 is :", _totalPopulation)
  59. #
  60.  
  61. #---------------- EVERYTHING BEFORE THIS IS CONSIDERED COMPILED -----------
  62.  
  63. class C3 (C1, C2) :
  64.     def say (self) :
  65.         # I want C2.say first and then C1.say twice
  66.         C2.say (self)
  67.         C1.say (self)
  68.         C1.say (self)
  69.     #
  70. #
  71.  
  72. obj1 = C3 ()
  73. obj2 = C3 ()
  74. c1TalksToC2 (obj1, obj2)
  75.  
  76. totalPopulationOfC1AndC2 ()
Advertisement
Add Comment
Please, Sign In to add comment