By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

Design a new class or inheritance or else?

P: n/a
Dear all,

I'm using a commercial library that I cannot modify. There's this one
class in the library which is almost 90% usable. But unfortunately, I
have to reimplement 3 member functions. The problem is the original
class is not designed very well, because it is assumed to be the final
class. Because I have to modify some private members in the
reimplemented functions. What should I do? Design a new class or doing
something else?

Here is the detailed information:
I have to design a Label class which can show both bitmap and text.
I'm using QT as my base library. QT has a class named QLabel, but it
only supports either bitmap or text. QLabel has two virtual functions,
one is setText, and another is setPixmap, but they eliminate the other
one when being called. So I have to reimplement the two functions. But
the problem is the text and bitmap members are private in QT, and
there's no other functions to set the values other than setText and
setPixmap. So what should I do? Simply copy the code and design a new
class according to QLabel or else?

Thanks in advance!
Jack
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Jack" <zh******@263.net> wrote in message
news:b8**************************@posting.google.c om...
....
I have to design a Label class which can show both bitmap and text.
I'm using QT as my base library. QT has a class named QLabel, but it
only supports either bitmap or text. QLabel has two virtual functions,
one is setText, and another is setPixmap, but they eliminate the other
one when being called. So I have to reimplement the two functions. But
the problem is the text and bitmap members are private in QT, and
there's no other functions to set the values other than setText and
setPixmap. So what should I do? Simply copy the code and design a new
class according to QLabel or else?


I would recommend replicating the code and making your own parallel
implementation.
This is probably the least likely to 'break' with later versions of your
library, and will give you more freedom if you later need to make additional
changes (e.g. controlling the relative placement of the text and image).

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Jul 22 '05 #2

P: n/a
In article <b8**************************@posting.google.com >,
zh******@263.net (Jack) wrote:
Dear all,

I'm using a commercial library that I cannot modify. There's this one
class in the library which is almost 90% usable. But unfortunately, I
have to reimplement 3 member functions. The problem is the original
class is not designed very well, because it is assumed to be the final
class. Because I have to modify some private members in the
reimplemented functions. What should I do? Design a new class or doing
something else?

Here is the detailed information:
I have to design a Label class which can show both bitmap and text.
I'm using QT as my base library. QT has a class named QLabel, but it
only supports either bitmap or text. QLabel has two virtual functions,
one is setText, and another is setPixmap, but they eliminate the other
one when being called. So I have to reimplement the two functions. But
the problem is the text and bitmap members are private in QT, and
there's no other functions to set the values other than setText and
setPixmap. So what should I do? Simply copy the code and design a new
class according to QLabel or else?


I would use two QLabel objects. Put them both in a single class that is
in charge of making sure they are properly positioned relitive to each
other.
Jul 22 '05 #3

P: n/a
zh******@263.net (Jack) wrote in message news:<b8**************************@posting.google. com>...
Dear all,

I'm using a commercial library that I cannot modify. There's this one
class in the library which is almost 90% usable. But unfortunately, I
have to reimplement 3 member functions. The problem is the original
class is not designed very well, because it is assumed to be the final
class. Because I have to modify some private members in the
reimplemented functions. What should I do? Design a new class or doing
something else?

Here is the detailed information:
I have to design a Label class which can show both bitmap and text.
I'm using QT as my base library. QT has a class named QLabel, but it
only supports either bitmap or text. QLabel has two virtual functions,
one is setText, and another is setPixmap, but they eliminate the other
one when being called. So I have to reimplement the two functions. But
the problem is the text and bitmap members are private in QT, and
there's no other functions to set the values other than setText and
setPixmap. So what should I do? Simply copy the code and design a new
class according to QLabel or else?

Thanks in advance!
Jack


Though this is a bit off-topic:

Create your own widget (derived from QWidget or QFrame (*)) and give it
2 members QLabel: one carrying the bitmap and one carrying the text.
Create a nice, small custom widget and register is designer.

(*) depends if you need signals or not.

Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.