The following codes illustrate a case where I am not sure whether I should define another class or just leave it within one class:
class Abc
{
public:
int def;
bool bDef;
void perform()
{
do_first();
do_second();
if(bDef)
{
do_the_third(def);
}
}
}
In this class Abc, in most cases there is no need to define bDef and def. When they are defined it will perform something different. It is also possible to separate it into two classes:
class Abc
{
public:
void perform()
{
do_first();
do_second();
}
protected:
do_first();
do_second();
}
class Def: public Abc
{
public:
int def;
void perform()
{
do_first();
do_second();
do_the_third(def);
}
}
So here is my question: which way of implementation is better? Thanks.
Aucun commentaire:
Enregistrer un commentaire