Q
qazmlp
class base
{
// other members
public:
virtual ~base()
{
}
virtual void virtualMethod1()=0 ;
virtual void virtualMethod2()=0 ;
virtual void virtualMethod3()=0 ;
} ;
I derive a class from base. I want to make all the virtual functions
as private.
class derived : public base
{
// other members
public:
virtual ~derived()
{
}
void myPublicInterface1() ;
void myPublicInterface1() ;
private:
virtual void virtualMethod1()=0 ;
virtual void virtualMethod2()=0 ;
virtual void virtualMethod3()=0 ;
} ;
I did the above considering the facts that
- in any case, the virtual functions will always be called through
the base class pointer only
- No. of public virtual interfaces should be reduced as much as
possible
Here are my questions:
1)
Can I consider this as a good design? If yes/no, why?
2)
How about
class derived : private base
{
}
instead of the above design, as anyway, all the inherited virtual
functions need to be made as private ?
Is this a correct design? If yes/no, why?
3)
What are the flaws in the above design and what do you suggest for
improvements?
{
// other members
public:
virtual ~base()
{
}
virtual void virtualMethod1()=0 ;
virtual void virtualMethod2()=0 ;
virtual void virtualMethod3()=0 ;
} ;
I derive a class from base. I want to make all the virtual functions
as private.
class derived : public base
{
// other members
public:
virtual ~derived()
{
}
void myPublicInterface1() ;
void myPublicInterface1() ;
private:
virtual void virtualMethod1()=0 ;
virtual void virtualMethod2()=0 ;
virtual void virtualMethod3()=0 ;
} ;
I did the above considering the facts that
- in any case, the virtual functions will always be called through
the base class pointer only
- No. of public virtual interfaces should be reduced as much as
possible
Here are my questions:
1)
Can I consider this as a good design? If yes/no, why?
2)
How about
class derived : private base
{
}
instead of the above design, as anyway, all the inherited virtual
functions need to be made as private ?
Is this a correct design? If yes/no, why?
3)
What are the flaws in the above design and what do you suggest for
improvements?