I am trying to find the best design for several classes that store data. For all I know I could do something with inheritance:
struct Data
{
int a;
int b;
int c;
};
struct DerivedData : public Data
{
int d;
};
struct AnotherDerivedData : public Data
{
int e;
};
Or with composition:
struct ComposedData
{
Data data;
int d;
};
struct AnotherComposedData
{
Data data;
int e;
};
I am leaning towards inheritance because there is a relationship between Data and DerivedData. But I was wondering if it was good design since there are absolutely no functions to be inherited ?
Moreover, Data should not be used on its own, so I was wondering if I could make it abstract and if it was worth it ? I've read that to do that, you should make a pure virtual destructor or preferably a protected constructor:
struct Data
{
int a;
int b;
int c;
protected:
Data() = default;
};
But what I don't like here is that it introduces a bit of complexity in an otherwise simple struct. It is not even a POD (if I understood what PODs are correctly).
Any advice on what would be the best implementation ? Are there any other ways to do it ?
Edit: I realize I was not clear enough about what is mainly bothering me: There is a "is-a" relationship between DerivedData and Data. But for some reason, I am feeling like inheritance is a bit "excessive" because there are no functions to be overriden (and even no function at all). But maybe this is a misconception on my part and that inheritance is totally appropriate here ?