473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2349
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.Container 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*********@hotmail.com wrote in message news:<c7**************************@posting.google. 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.provided> wrote in message news:<7a******************@nasal.pacific.net.au>.. .
I think I would probably have CompositeIsoWidget 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
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. ...
9
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...
3
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...
7
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...
2
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...
2
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
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...
18
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....
26
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.