Re: Design problem with inheritance
- From: "Daniel T." <daniel_t@xxxxxxxxxxxxx>
- Date: Thu, 13 Jul 2006 14:36:36 GMT
In article <1152794992.158364.16180@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
srinivasarao_moturu@xxxxxxxxx wrote:
class ABC
{
public :
virtual void operation1();
virtual void operation2();
virtual int GetValue();
virtual char GetValue();
virtual void SetValue(int);
virtual void SetValue(char);
}
class intABC : public ABC
{
public :
virtual void operation1();
virtual void operation2();
void SetValue(int);
int GetValue();
private:
int val;
}
class charABC : public ABC
{
public :
virtual void operation1();
virtual void operation2();
void SetValue(char);
char GetValue();
private :
char val;
}
class Controler
{
public :
//constructors and destructors
void somefunc() //this function handles container member
private :
vector<ABC*> val;
}
client Controler class manipulates ABC derived classes polymorphically
I feel, In the above design surely it is not following Lispov
substitution principle.
here ABC is a fatty interface since intABC does not require char
version of get/set membersand charABC does not require int version of
get/set members.
If I remove Get/Set members from ABC class and put int versions in
intABC and char versions in charABC then I have to use downcasting to
call specific versions.
so is there a good design to remove fatty interface from the ABC and at
the same time i should not use downcasting and another constraint is I
should use ABC polymorphically?
At the point that GetValue and SetValue are actually called, the caller
must know if it is dealing with a intABC or a charABC *even if no
down-casting takes place*. You need to look at your code and figure out
how it knows which are which and pass that knowledge explicitly through
the system rather than leaving it implicit.
.
- References:
- Design problem with inheritance
- From: srinivasarao_moturu
- Design problem with inheritance
- Prev by Date: Re: Persistence
- Next by Date: Re: Observer pattern limitations
- Previous by thread: Re: Design problem with inheritance
- Next by thread: Re: Design problem with inheritance
- Index(es):
Relevant Pages
|