C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Design problem with inheritance

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Jul 14, 2006 2:28 am    Post subject: Design problem with inheritance Reply with quote



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 members
and 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?

With Regards,
sri.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Guest






PostPosted: Sun Jul 16, 2006 2:35 am    Post subject: Re: Design problem with inheritance Reply with quote



whiteflags99 (AT) hotmail (DOT) com wrote:
Quote:
here ABC is a fatty interface since intABC does not require char
version of get/set members
and 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?

I believe you have two possible paths to take: You can make the getters
and setters pure virtual methods, requiring the derived classes to
implement their own, or you can make ABC a template class.

These two ways are not so good. The first one doesn't solve design
drawback, of which derived class's implementation detail is exposed in
base class. The second one, template, whose pointer are treated as two
independent classes and thus can't be used in one container.

I think the only choice is to use downcasting when you get base class's
pointer from container and call setter/getter from casted derived class
pointer.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.