我有许多类与基类及其继承形成类层次结构。每个类都相当大,承担了几个职责,尽管这些职责不是耦合的。我将不同的职责放在一个类中,因为我可以很容易地一致地使用它们(我不能很清楚地表达出来,请参阅说明代码)。但这似乎不是一个好的设计。如何在保持易于使用的同时拆分大类?感谢您的建议和意见!下面请找到说明代码。
// Base class.
class Base
{
public:
// For responsibility A
virtual void A1();
virtual void A2();
...
// For responsibility B
virtual void B1();
virtual void B2();
...
// More responsibilites.
...
};
// Derived class 1.
class Derived_1 : public Base
{...};
// More derived classes.
...
// A function use it.
void Fun()
{
Base* p = new Derived_1;
p->A1(); // Here A1 and B1 are binded in the class Base, thus it make sure
p->B1(); // their uses are consistent. If they are separated, how to ensure it?
}