Title edits that reflect a better summary of the question are welcome.
I'd like to refactor these three classes somehow to remove the duplicate field represented in class C
(see hierarchy). I thought about pulling the field up into a parent class, but the issue is that A and B are not similar enough to be considered "is-a", C is considered both, and it is literally only one member field so creating a class just to hold ONE THING seems a bit overkill.
Hierarchy:
(abstract data type)
class A : public O {
public:
//...
std::string GetName();
std::string GetName() const;
void SetName(std::string name);
//...
protected:
//...
std::string _name;
//...
};
//Methods and fields shown here represent the exact same representative data as in A but the classes are so dissimilar as to not be considered "is-a" relationship.
(abstract data type)
class B {
public:
//...
std::string GetName();
std::string GetName() const;
void SetName(std::string name);
//...
protected:
//...
std::string _name;
//...
};
(concrete)
class C : public A, public B {
public:
//...
C(/*..Other parameters..*/, std::string name, /*....*/)
: A(name, /*...*/), B(name, /*...*/) {
/*...*/
}
//...
private:
//...
};