Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- class IContent(ABC):
- def __init__(self, text):
- self.text = text
- @abstractmethod
- def format(self):
- pass
- class MyContent(IContent):
- def format(self):
- return ''.join(['<MyML>', self.text, '</MyML>'])
- class IProtocol(ABC):
- def __init__(self, text):
- self.text = text
- @abstractmethod
- def format(self):
- pass
- class MyProtocol(IProtocol):
- def format(self):
- return ''.join(["I'm" , self.text])
- class IEmail(ABC):
- @abstractmethod
- def set_sender(self, sender):
- pass
- @abstractmethod
- def set_receiver(self, receiver):
- pass
- @abstractmethod
- def set_content(self, content):
- pass
- class Email(IEmail):
- def __init__(self, protocol):
- self.protocol = protocol
- self.__sender = None
- self.__receiver = None
- self.__content = None
- def set_sender(self, sender):
- self.__sender = sender.format()
- def set_receiver(self, receiver):
- self.__receiver = receiver.format()
- def set_content(self, content):
- self.__content = content.format()
- def __repr__(self):
- template = "Sender: {sender}\nReceiver: {receiver}\nContent: \n{content}"
- return template.format(sender = self.__sender, receiver = self.__receiver, content = self.__content)
- email = Email('IM')
- email.set_sender('qmal')
- email.set_receiver('james')
- content = MyContent('Hello, there!')
- email.set_content(content)
- print(email)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement