Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class Notification
  6. {
  7.     public:
  8.     virtual void notify(std::string mSubject)=0;
  9.    
  10. };
  11.  
  12. class WAppNotification : public Notification
  13. {
  14.     public:
  15.     void notify (std::string mSubject) override
  16.     {
  17.          std::cout << "Whatsapp " << mSubject << "\n";
  18.     }
  19. };
  20.  
  21. class MailNotification : public Notification
  22. {
  23.     public:
  24.     void notify (std::string mSubject) override
  25.     {
  26.         std::cout << "Mail " << mSubject << "\n";
  27.     }
  28. };
  29.  
  30. class User
  31. {
  32. private:
  33.     Notification * _notification;
  34.  
  35. public:
  36.     User()
  37.     {
  38.         _notification = new MailNotification();
  39.     }                                  
  40.     ~User()
  41.     {
  42.         delete(_notification);
  43.     }
  44.  
  45.     void send(std::string mSubject)
  46.     {
  47.         //Solo envia las notificaciones bien a Mail
  48.         _notification->notify(mSubject);
  49.     }
  50.  
  51.     void setWAppNotification()
  52.     {
  53.         // Borro el _notification -> Ahora era de Type MailNotification()
  54.         delete(_notification);
  55.         Notification * n;
  56.         n = new WAppNotification();
  57.         // Aqui quiero asignar a Notification *_notification el Type WAppNotification()
  58.         setNotificationType(n);
  59.     }
  60.  
  61.     void setNotificationType (Notification * mNotification)
  62.     {
  63.         _notification = mNotification;
  64.     }
  65. };
  66.  
  67. int main()
  68. {
  69.    User user;
  70.    
  71.    user.send("primer mensaje");
  72.    user.setWAppNotification();
  73.    user.send("segundo mensaje");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement