473,770 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design a new class or inheritance or else?

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
3 1573
"Jack" <zh******@263.n et> wrote in message
news:b8******** *************** ***@posting.goo gle.com...
....
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
In article <b8************ **************@ posting.google. com>,
zh******@263.ne t (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
zh******@263.ne t (Jack) wrote in message news:<b8******* *************** ****@posting.go ogle.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
1984
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point to the parent in the inheritance tree). 2. This hierarchy evolved over time to different versions for each class. So for example, version's 1 hierarchy would be A_v1 <-B_v1 <-..<-Z_v1. 3. At runtime, only one version is selected by a factory...
8
1854
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On what arguments do you decide whether to pass a reference to the object of class B to the member function like this operator()(classB& objB) or to have in class A a data member (a const pointer to a class B object or so) and have this set during...
4
1609
by: Merlin | last post by:
Hi Imagine the following classes (A class diagram will help) BASE, A, B, C, D, E, F, G. A, B, C, D, G inherit from BASE. E, F inherit from D.
0
1865
by: JKJ | last post by:
I'm not an OOP guru, but I would say ". . .not necessarily" What if the base class and derived classes are internal? Then the base class has to be within the same assembly to be inherited from. You may want to create several classes that are used throughout the assembly, but are not accessible outside the assembly. . . If your base class will be inherited across multiple assemblies and future applications, then I would then
14
1579
by: Mark O'Flynn | last post by:
I would like some advice regarding implementing inheritance using vb.net. I have an application written in vb6 that I am rewritting from the ground up in vb.net to take full advantage of .net, but I have encountered a design issue implementing inheritance. To explain my question, I will use an example. I have a Person class, with properties such as ID, Name, Phone, Address etc. I then have a Manager class that inherits Person and...
20
1536
by: Brad Pears | last post by:
I am completely new to vb .net. I am using visual Studio 2005 to redo an Access 2000 application into a .net OO application using SQL Server 2000 - so a complete rewrite and re-thinking of how this app will work. I have NEVER done any OO programming at all although I have used OO techniques in programs of course - just never actually designed the classes etc... So I am just a tad nervous in re-writing this Access application as it is...
4
1771
by: nw | last post by:
Hi, I was wondering if someone would be able to give me some comments on the following class structure, it feels to me as if there must be a better way, but I'm unsure what it is, perhaps I should be using multiple inheritance? Basically I have a pure virtual class called Body, this contains a number of integration algorithms which are applied to the Body. Generally only one integration algorithm will be used with a
7
3069
by: snewman18 | last post by:
In learning about design patterns, I've seen discussion about using inheritance when an object's relationship to another object is 'is-a' and composition when the relationship is 'has-a'. Since this is all new and I'm still learning, I was hoping someone can give me some pointers on best practices on applying these ideas. If my logic is incorrect on anything, please don't hesitate to tell me where I'm wrong - I'm completely open to any...
7
1720
by: Immortal Nephi | last post by:
I have an idea how to design an object in a better way. I would like to give you my thought example. Please let me know what you think if it is best object design. Please recommend me any book which it teaches me how to design C++ OOP better as long as I know how to program OOP in C++. Think of ancient 6502 microprocessor which it was used for Commodore, Atari, and Apple II. This MPU_6502 is an object of MPU_6502 class. All member
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.