vendredi 4 août 2023

Design Pattern to adding new capability to my class

I'm trying to find a solution for my structure. Let me try to tell what I am doing.

I have two class "Englishman" and "CanadaMan" and some capability classes "CanSpeakEnglish", "CanSpeakFrench"

class CanTalkEnglish{
    Database database;
    void TalkEnglish(){
      Console.Write(" am taking {this.database.MyLanguage}");
    } 
};

class CanTalkFrench{
    Database database;
    void TalkFrench(){
      Console.Write("Je parle {this.database.MyLanguage}");
    }
};

class Englishman : public CanTalkEnglish {
    Database database;
    void Talk(){
       if (this->database.Mood == "OpenToCommunication"){
         this->TalkEnglish();
       }
   }
};

class CanadaMan : public CanTalkEnglish,CanTalkFrench {
    Database database;
    void Talk(){
       if (this->database.Mood == "OpenToCommunication"){
         this->TalkEnglish();
         this->TalkFrench();
       }
   }
};

This is the structure that I imagine, but the problem is the "database". All "Person" classes and all "Capability" classes will need it. But this.database call is ambiguous, is there a design pattern to manage this kind of requirement?

Aucun commentaire:

Enregistrer un commentaire