I am looking for advice on the most elegant and secure way to decouple two C++ classes that maintain collections of pointers to each other's types.
I implemented it recently using a common base class for polymorphism and was told that it was an unsatisfactory solution. I am eager to learn other ways this can be achieved.
Thanks in advance...
I have added a simplified version of the class definitions below. I am aware that the SalesTeam
class is not decoupled from SalesPerson
here.
// Global Vectors
vector<Customer *> v_Customer;
vector<SalesPerson *> v_SalesPerson;
vector<SalesTeam *> v_SalesTeam;
class Person { // Base Class
};
class Customer: public Person {
private:
const Person *contact; // This is the SalesPerson that serves the Customer
public:
Customer(const int aBirthYear);
virtual ~Customer() {}
};
class SalesPerson: public Person {
private:
vector<Person *> v_Client; // These are the customers that the SalesPerson serves
public:
SalesPerson();
virtual ~SalesPerson(){};
};
class SalesTeam {
private:
vector<SalesPerson *> v_TeamMember; // These are the sales people in the SalesTeam
public:
SalesTeam();
};