Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- /** The interfaces of the talkers */
- class salute_interface { /* Abstract Class */
- public:
- virtual void mucho_gusto () = 0;
- virtual void bien_y_vos () = 0;
- virtual void begin_chatter () = 0;
- };
- class respond_interface { /* Abstract Class */
- public:
- virtual void hola () = 0;
- virtual void como_estas () = 0;
- };
- /** The concrete talkers */
- class first_talker : public salute_interface {
- private:
- respond_interface * interlocutor;
- bool has_greeted;
- public:
- void mucho_gusto () {
- has_greeted = true;
- cout << "Mucho gusto \n" ;
- interlocutor -> como_estas ();
- };
- void bien_y_vos () {
- if (has_greeted){
- cout << "Bien, y vos? \n" ;
- }
- };
- void begin_chatter () {
- interlocutor -> hola ();
- };
- void initialize (respond_interface * talker) {
- has_greeted = false;
- interlocutor = talker;
- };
- };
- class second_talker : public respond_interface {
- private:
- salute_interface * interlocutor;
- bool has_been_greeted;
- public:
- void hola () {
- has_been_greeted = true;
- cout << "Hola \n" ;
- interlocutor -> mucho_gusto ();
- };
- void como_estas () {
- if (has_been_greeted) {
- cout << "Como estas? \n" ;
- interlocutor -> bien_y_vos ();
- }
- };
- void initialize (salute_interface * talker) {
- has_been_greeted = false;
- interlocutor = talker;
- };
- };
- int main (void) {
- first_talker * ft;
- second_talker * st;
- ft = new (first_talker);
- st = new (second_talker);
- ft -> initialize (st);
- st -> initialize (ft);
- ft -> begin_chatter ();
- delete (ft);
- delete (st);
- return 0;
- }
Add Comment
Please, Sign In to add comment