Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- class Notification
- {
- public:
- virtual void notify(std::string mSubject)=0;
- };
- class WAppNotification : public Notification
- {
- public:
- void notify (std::string mSubject) override
- {
- std::cout << "Whatsapp " << mSubject << "\n";
- }
- };
- class MailNotification : public Notification
- {
- public:
- void notify (std::string mSubject) override
- {
- std::cout << "Mail " << mSubject << "\n";
- }
- };
- class User
- {
- private:
- Notification * _notification;
- public:
- User()
- {
- _notification = new MailNotification();
- }
- ~User()
- {
- delete(_notification);
- }
- void send(std::string mSubject)
- {
- //Solo envia las notificaciones bien a Mail
- _notification->notify(mSubject);
- }
- void setWAppNotification()
- {
- // Borro el _notification -> Ahora era de Type MailNotification()
- delete(_notification);
- Notification * n;
- n = new WAppNotification();
- // Aqui quiero asignar a Notification *_notification el Type WAppNotification()
- setNotificationType(n);
- }
- void setNotificationType (Notification * mNotification)
- {
- _notification = mNotification;
- }
- };
- int main()
- {
- User user;
- user.send("primer mensaje");
- user.setWAppNotification();
- user.send("segundo mensaje");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement