Advertisement
chzchz

Untitled

Mar 29th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void SendSms(const string& number, const string& message) {
  7.   cout << "Send '" << message << "' to number " << number << endl;
  8. }
  9.  
  10. void SendEmail(const string& email, const string& message) {
  11.   cout << "Send '" << message << "' to e-mail " << email << endl;
  12. }
  13.  
  14. class INotifier {
  15. public:
  16.   virtual void Notify(const string& message) const = 0;
  17. };
  18.  
  19. class SmsNotifier : public INotifier {
  20. public:
  21.   SmsNotifier(const string& number)
  22.     : Number(number)
  23.   {
  24.   }
  25.   virtual void Notify(const string& message) const override {
  26.     SendSms(Number, message);
  27.   }
  28.  
  29. private:
  30.   const string Number;
  31. };
  32.  
  33. class EmailNotifier : public INotifier {
  34. public:
  35.   EmailNotifier(const string& email)
  36.     : Email(email)
  37.   {
  38.   }
  39.   virtual void Notify(const string& message) const override {
  40.     SendEmail(Email, message);
  41.   }
  42.  
  43. private:
  44.   const string Email;
  45. };
  46.  
  47. void Notify(const INotifier& notifier, const string& message) {
  48.   notifier.Notify(message);
  49. }
  50.  
  51. int main() {
  52.   SmsNotifier sms{"+7-495-777-77-77"};
  53.   EmailNotifier email{"na-derevnyu@dedushke.ru"};
  54.  
  55.   Notify(sms, "I have White belt in C++");
  56.   Notify(email, "And want a Yellow one");
  57.   return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement