I am facing a design challenge with my classes and being new to C++ and OOP I am hoping I can get some advice on how this should be handled.
The situation is that for example I have 2 (and in the future more) variations of a Customer class that I want to treat as a single member variable of the Project class. The different Customer classes do not share much in common because they are intended to be used to store data pulled from different APIs.
The code for example purposes would be as follows (ignoring lack of constructors/destructors etc. for the purposes of discussion)
class Project
{
Customer customer; //???
}
class Customer1
{
std::string name;
std::string address;
}
class Customer2
{
std::string name;
std::string primary_contact
bool approved;
}
My initial idea was to use polymorphism and create an abstract base class AbstractCustomer and make Customer1 and Customer2 derive from this base class. This way I would only have 1 member variable of AbstractCustomer* customer inside Project and be able to effectively build in logic to dynamically determine which Customer subclass is needed.
My dumb option was to simply have separate member variables e.g. Customer1* customer1 & Customer2* customer2 which are pointers and then effectively use a nullptr to indicate which ones are not in use. This however doesn't feel right and of course when more Customer class variations come up then I would need to keep adding more member variables to the Project class.
note: I am using these classes more for POD purposes and don't envisage having many methods, which is why I am unsure about using interfaces/abstract classes since it seems that's where the benefits of it lie.
Any advice/guidance is appreciated.