Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on Dec 11, 2018
- @author: Erik Pohl
- '''
- """
- Adapter changes the interface of a class into the interface a client expects.
- Adapter adapts the interface so that classes can work together which otherwise
- wouldn't.
- """
- import abc
- class Land_Target(metaclass=abc.ABCMeta):
- """
- Define the interface that Client expects based on its domain.
- """
- def __init__(self):
- self._fish_adaptee = Fish_Adaptee()
- @abc.abstractmethod
- def move_on_land_request(self):
- pass
- class Legs_Spiracles_Adapter(Land_Target):
- """
- Adopt the Target interface for the interface of Adaptee
- """
- def move_on_land_request(self):
- self._fish_adaptee.move_in_water_specific_request()
- class Fish_Adaptee:
- """
- This interface needs to adapt to work in a different domain
- """
- def move_in_water_specific_request(self):
- print("I can adapt to new environments")
- def main():
- adapter = Legs_Spiracles_Adapter()
- adapter.move_on_land_request()
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment