473,799 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with OO design problem

Hi all,

Here's my problem. I have a design where the class Container inherits
class Widget, and is used to contain and handle the proper display of
widgets and behaves like a widget itself. I have a class IsoWidget
which inherits from class Widget which is used to display isometric
widgets. I want to make a class IsoContainer (which contains
IsoWidgets and behaves like an IsoWidget), and since an IsoContainer
seems like it should inherit from both IsoWidget and Container, I'm
not sure what's best.

I see a few options as of now:
- Use multiple inheritance (ick) to resolve the issue by having
IsoContainer inherit from Container and IsoWidget.
- Copy code from IsoWidget and dump it into IsoContainer (ick)
- Copy code from Container and dump it into IsoContainer (worse)
- Redesign the entire class hierarchy, breaking nearly everything
else, but resulting in a better design.

Does anyone see a better solution? Help!

Thanks in advance,
Soulshift
Jul 19 '05 #1
5 2372
Another idea:

template<class Item> class Composite : public Item
{
public:
void add(Item *);
// etc.
};

With this you can have a composite anything.

DW

Jul 19 '05 #2
PS> I'm sort of confused here. So, the class Container inherits from the
PS> class Widget, and is also used to contain instances of Widget?

This concept is (was) common in java 1.1.3, the good old AWT.
There you have a Component that is much like a Widget. Then
java.awt.Contai ner inherits Component AND has the ability to store
Components. I guess it's like inheriting from Box to make a Closet.
You pack your Closet full of Boxes, while your Closet itself IS a Box.

-X

Jul 19 '05 #3
pu*********@hot mail.com wrote in message news:<c7******* *************** ****@posting.go ogle.com>...
And just
what you are doing inheriting containers from the things they
contain I can't imagine.


It does make sense in some cases, and is a very powerful technique.
For example, an XyGraph object consists of many smaller objects -
axes, traces, labels etc. It makes things easier if each of those
smaller objects is derived from the same base class, say,
DrawableObject. Since the entire XyGraph object is also a thing that
is drawn, it makes sense if it is also derived from DrawableObject.
The XyGraph's Draw member would in turn call the Draw member of each
of its component objects. Also, the trace objects, for example, might
be made up of many line objects, each of which is also a
DrawableObject. Generalized, this technique enables you to build up a
DrawableObject of any complexity and depth, with both most complex
objects and the simplest of their components having the same base
class and interface.

DW

P.S. I've had to join Google temporarily, because my ISP's newsreader
is down.
Jul 19 '05 #4
j
> I'm sort of confused here. So, the class Container inherits from the
class Widget, and is also used to contain instances of Widget?
So you've got a parking lot that is a type of car? Or you can use
the instance of the parking lot to drive the car? Really not sure
I'm seeing what you are up to here.


it's a parking lot for parkinglots, you're confusing things.

J
Jul 19 '05 #5
"David White" <no@email.provi ded> wrote in message news:<7a******* ***********@nas al.pacific.net. au>...
I think I would probably have CompositeIsoWid get derived from IsoWidget.
Since the standard library probably already has all the container support
you need, I don't see a problem with whatever duplication there would be
with CompositeWidget .

You could also consider protected inheritance, which allows you to inherit
the implementation of a general-purpose container class that does most of
the work, while the public interface of each composite Widget class only
allows the correct kind of Widgets.

DW


Thanks for the suggestions. Probably the only thing that will work is
the template idea, as the behaviour of a CompositeWidget is not
trivially duplicatible. Implementing a template solution will take a
lot of work, but it's good to know that there is a nice way to do it.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7115
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
9
2939
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
3
10670
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
7
2361
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
2
1954
by: David | last post by:
SUMMARY: If you don't want to read all of this, what I'm looking for more or less is ideas on how to implement websites using ASP.NET that have a templated look and feel and many pages that make use of a template design. Hi- I'm new to ASP.NET and have been working for about 2 weeks on learning ASP.NET but it all still seems very murky to me. I've programmed sites in PHP and MySQL and also done programming in C++ and Java but I
2
1387
by: Bob Heitzman | last post by:
I need to store data in, update, and read data from an XML file. An INI structure worked fine: a= 123 b= xyz c= etc
21
3227
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
18
2344
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before. Here's the scenario: We have a base class with all virtual functions. We'll call this the Animal class. We then make two classes Fish and Bird that both inherit from Animal. In the program, we have a single array of Animal pointers that will...
26
2355
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
2
2050
by: jmDesktop | last post by:
I'm using C#, but I don't know that it matters for this question. I know that many experienced folks are on here, so sorry for being off topic. I am finally at a point where I want to and I think able to design software that is modular and pluggable. The only problem is that I'm not sure if I need to or if this lends itself to it. I have a project that requires building a scheduler. It's more of a virtual take number program as in...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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
10490
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...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9078
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...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3
2941
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.