Guest User

Untitled

a guest
Dec 11th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. '''
  2. Created on Dec 11, 2018
  3.  
  4. @author: Erik Pohl
  5. '''
  6.  
  7.  
  8. """
  9. Adapter changes the interface of a class into the interface a client expects.
  10. Adapter adapts the interface so that classes can work together which otherwise
  11. wouldn't.
  12. """
  13.  
  14. import abc
  15.  
  16.  
  17. class Land_Target(metaclass=abc.ABCMeta):
  18. """
  19. Define the interface that Client expects based on its domain.
  20. """
  21.  
  22. def __init__(self):
  23. self._fish_adaptee = Fish_Adaptee()
  24.  
  25. @abc.abstractmethod
  26. def move_on_land_request(self):
  27. pass
  28.  
  29.  
  30. class Legs_Spiracles_Adapter(Land_Target):
  31. """
  32. Adopt the Target interface for the interface of Adaptee
  33. """
  34.  
  35. def move_on_land_request(self):
  36. self._fish_adaptee.move_in_water_specific_request()
  37.  
  38.  
  39. class Fish_Adaptee:
  40. """
  41. This interface needs to adapt to work in a different domain
  42. """
  43.  
  44. def move_in_water_specific_request(self):
  45. print("I can adapt to new environments")
  46.  
  47.  
  48. def main():
  49. adapter = Legs_Spiracles_Adapter()
  50. adapter.move_on_land_request()
  51.  
  52.  
  53. if __name__ == "__main__":
  54. main()
Add Comment
Please, Sign In to add comment