Re: Design problem with inheritance



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.
.



Relevant Pages

  • Re: How to redesign big switch case?
    ... > I wrote an editor that reads chars, and does a switch to process ... if char is HOME then go to the beginning of the ... it would be nice to allow users to derive their own editor class ... virtual void onKey ...
    (comp.lang.cpp)
  • Re: Design problem with inheritance
    ... virtual void operation1; ... virtual int GetValue; ... virtual char GetValue; ... class charABC: public ABC ...
    (comp.object)
  • Re: Design problem with inheritance
    ... virtual void operation1; ... virtual int GetValue; ... virtual char GetValue; ... class charABC: public ABC ...
    (comp.object)
  • Design problem with inheritance
    ... virtual void operation1; ... virtual int GetValue; ... virtual char GetValue; ... class intABC: public ABC ...
    (comp.object)
  • Re: OT: C++ help
    ... virtual void f; ... int main{ ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)