Advertisement
Guest User

Untitled

a guest
May 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class Super:
  2. def method(self):
  3. print('in Super.method') # Default behavior
  4. def delegate(self):
  5. self.action() # Expected to be defined
  6. class Inheritor(Super): # Inherit method verbatim
  7. pass
  8. class Replacer(Super): # Replace method completely
  9. def method(self):
  10. print('in Replacer.method')
  11. class Extender(Super): # Extend method behavior
  12. def method(self):
  13. print('starting Extender.method')
  14. Super.method(self)
  15. print('ending Extender.method')
  16. class Provider(Super): # Fill in a required method
  17. def action(self):
  18. print('in Provider.action')
  19. if __name__ == '__main__':
  20. for klass in (Inheritor, Replacer, Extender):
  21. print('\n' + klass.__name__ + '...')
  22. klass().method()
  23. print('\nProvider...')
  24. x = Provider()
  25. x.delegate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement