Hello
Can anyone assist with the following class hierarcy problem?
I have a series of window classes, the object model currently being as such:
Window
/ | \
/ | \
MDIClientWindow | TreeViewWindow
WndProcWindow
/ \
/ \
DualPaneWindow SplitterWindow
i.e., the base class is Window. It has three direct subclasses,
MDIClientWindow, WndProcWindow, and TreeViewWindow. WndProcWindow also has
two further classes deriving from it, DualPaneWindow and SplitterWindow.
(MDIClient- and TreeView- don't have their own WndProcs)
Now, I am having the following problem: I want to create a few pure virtual
methods on the base Window class, in order that I can create a function that
will take a Window* and call a certain method on a [Something]Window,
knowing that it will have it - e.g. Create()=0. This will make Window a pure
abstract class, this is fine. However, I have been scratching my head as to
the best way to implement this, because WndProcWindow is already an abstract
class - it has a pure virtual method, WndProc.
I'd like to make Window an abstract class, with some methods e.g. Create(),
as pure virtual methods. But this would mean that WndProcWindow would have
to implement them, and it wouldn't be appropriate for it to. Is there any
neat way of getting around this, like some way of telling the compiler that
WndProcWindow won't actually implement the Size method, but any
instantiatable class deriving from it must, because it also derives from
Window?
e.g.
// (Window.h)
void Create(LPCTSTR class, DWORD style);
{
....(generic CreateWindow code here)
}
void Create() = 0; // ???
//WndProcWindow.h
LRESULT WndProc(...) = 0;
void Create(LPCTSTR, DWORD);
void Create(); // ???
//SplitterWindow.cpp
SplitterWindow::Create()
{
WndProcWindow::Create(RegisterClass(... "splitterclass", ...), WS_CHILD |
WS_VISIBLE);
}
//TreeViewWindow.cpp
TreeViewWindow::Create()
{
WndProcWindow::Create(WC_TREEVIEW, WS_CHILD | WS_VISIBLE);
}
//WndProcWindow.cpp
WndProcWindow::Create(LPCTSTR class, DWORD style)
{
Window::Create(class, style);
}
WndProcWindow::Create() //??? help! what goes here?....
{
}
I thought of one solution - multiple inheritance. This would solve it - as I
could have an abstract class, say CreatableWindow, that had the pure virtual
methods e.g. Size(...) = 0, and then DualPane-, MDIClient-, TreeView- and
SplitterWindow could all multiply inherit from WndProcWindow or Window, and
then CreatableWindow aswell. But I've heard horror stories about multiple
inheritance - and that MS says it's one of those "if you really must"
things. A hunch tells me a multiply-inheriting class is like an inbred. Is
my hunch right, will it slow down my code or lead to spaghetti code without
any real benefit, or is it a little-discovered, rarely used technology
that's perfect for this kind of scenario?
On this particular project the porting to other compilers isn't a problem as
I've used loads of VS specific features anyway, but I would like to know if
it is to be avoided or not? Is it a performance hit?
Thanks for any guidance on how to accomplish the above or suggestions on how
I can better structure this without ripping the design apart completely! (It
seems good apart from this...)
(I hope this doesn't seem irrelevant to c.l.c++ as it's really about classes
not windows...) 2 1735
Bonj schrieb: Hello Can anyone assist with the following class hierarcy problem? I have a series of window classes, the object model currently being as such:
Window / | \ / | \ MDIClientWindow | TreeViewWindow WndProcWindow / \ / \ DualPaneWindow SplitterWindow
i.e., the base class is Window. It has three direct subclasses, MDIClientWindow, WndProcWindow, and TreeViewWindow. WndProcWindow also has two further classes deriving from it, DualPaneWindow and SplitterWindow. (MDIClient- and TreeView- don't have their own WndProcs) Now, I am having the following problem: I want to create a few pure virtual methods on the base Window class, in order that I can create a function that will take a Window* and call a certain method on a [Something]Window, knowing that it will have it - e.g. Create()=0. This will make Window a pure abstract class, this is fine. However, I have been scratching my head as to the best way to implement this, because WndProcWindow is already an abstract class - it has a pure virtual method, WndProc. I'd like to make Window an abstract class, with some methods e.g. Create(), as pure virtual methods. But this would mean that WndProcWindow would have to implement them, and it wouldn't be appropriate for it to. Is there any neat way of getting around this, like some way of telling the compiler that WndProcWindow won't actually implement the Size method, but any instantiatable class deriving from it must, because it also derives from Window?
What makes you think that this is a problem?
class Window
{
public:
virtual ~Window() {}
virtual void Create() = 0;
};
class WndProcWindow : public Window
{
public:
virtual void WndProc() = 0;
};
class SplitterWindow : public WndProcWindow
{
public:
virtual void Create() { /* stuff */ }
virtual void WndProc() { /* stuff */ }
};
is perfectly valid. No need for WndProcWindow to implement any of
Window's pure virtuals as long as you don't want to instantiate
WndProcWindow - which you can't do anyway because of the pure virtual
WndProc().
I thought of one solution - multiple inheritance. This would solve it - as I could have an abstract class, say CreatableWindow, that had the pure virtual methods e.g. Size(...) = 0, and then DualPane-, MDIClient-, TreeView- and SplitterWindow could all multiply inherit from WndProcWindow or Window, and then CreatableWindow aswell. But I've heard horror stories about multiple inheritance - and that MS says it's one of those "if you really must" things. A hunch tells me a multiply-inheriting class is like an inbred. Is my hunch right, will it slow down my code or lead to spaghetti code without any real benefit, or is it a little-discovered, rarely used technology that's perfect for this kind of scenario?
*Never* trust any generalisations :-)
MI is a powerful tool for some situations and should be avoided for
others, I personally don't subscribe to the "if you really must" theory
nor a general ban on it. I would say you shouldn't use it unless you
really understand it though - but that goes for just about any
programming technique ;-)
Either way, there isn't much of a reason for you to use MI unless I
totally misunderstood your problem - it would be the perfect option to
go for if there e.g. might be a subclass of TreeViewWindow that also has
a WndProc.
Cheers,
Malte
"Malte Starostik" <ma***@starostik.de> wrote in message
news:42******@olaf.komtel.net... Bonj schrieb: Hello Can anyone assist with the following class hierarcy problem? I have a series of window classes, the object model currently being as such:
Window / | \ / | \ MDIClientWindow | TreeViewWindow WndProcWindow / \ / \ DualPaneWindow SplitterWindow
i.e., the base class is Window. It has three direct subclasses, MDIClientWindow, WndProcWindow, and TreeViewWindow. WndProcWindow also has two further classes deriving from it, DualPaneWindow and SplitterWindow. (MDIClient- and TreeView- don't have their own WndProcs) Now, I am having the following problem: I want to create a few pure virtual methods on the base Window class, in order that I can create a function that will take a Window* and call a certain method on a [Something]Window, knowing that it will have it - e.g. Create()=0. This will make Window a pure abstract class, this is fine. However, I have been scratching my head as to the best way to implement this, because WndProcWindow is already an abstract class - it has a pure virtual method, WndProc. I'd like to make Window an abstract class, with some methods e.g. Create(), as pure virtual methods. But this would mean that WndProcWindow would have to implement them, and it wouldn't be appropriate for it to. Is there any neat way of getting around this, like some way of telling the compiler that WndProcWindow won't actually implement the Size method, but any instantiatable class deriving from it must, because it also derives from Window? What makes you think that this is a problem?
class Window { public: virtual ~Window() {} virtual void Create() = 0; };
class WndProcWindow : public Window { public: virtual void WndProc() = 0; };
class SplitterWindow : public WndProcWindow { public: virtual void Create() { /* stuff */ } virtual void WndProc() { /* stuff */ } };
is perfectly valid. No need for WndProcWindow to implement any of Window's pure virtuals as long as you don't want to instantiate WndProcWindow - which you can't do anyway because of the pure virtual WndProc().
ah, yes - cheers, i didn't realise that you could do that, so that's pretty
much exactly what I've gone for. I thought of one solution - multiple inheritance. This would solve it - as I could have an abstract class, say CreatableWindow, that had the pure virtual methods e.g. Size(...) = 0, and then DualPane-, MDIClient-, TreeView- and SplitterWindow could all multiply inherit from WndProcWindow or Window, and then CreatableWindow aswell. But I've heard horror stories about multiple inheritance - and that MS says it's one of those "if you really must" things. A hunch tells me a multiply-inheriting class is like an inbred. Is my hunch right, will it slow down my code or lead to spaghetti code without any real benefit, or is it a little-discovered, rarely used technology that's perfect for this kind of scenario? *Never* trust any generalisations :-) MI is a powerful tool for some situations and should be avoided for others, I personally don't subscribe to the "if you really must" theory nor a general ban on it. I would say you shouldn't use it unless you really understand it though - but that goes for just about any programming technique ;-)
I've gone for a class 'ChildWindow' but this doesn't derive from the main
class, it is essentially just an interface, so it's like a 'V' shape but not
a diamond shape.
The SplitterWindow derives from this and Window, but I can see clearly that
only one 'copy' of each is being pulled in.
thanks
Either way, there isn't much of a reason for you to use MI unless I totally misunderstood your problem - it would be the perfect option to go for if there e.g. might be a subclass of TreeViewWindow that also has
I didn't know whether a TreeView could even have its own WndProc, but even
if it can I'm not going for that, I'm instead going to put something like
'HandleNotifier(code)=0' in the ChildWindow abstract class. However there
will be another class derived from TreeViewWindow - the treeview that's
specific to this particular application.
a WndProc.
Cheers, Malte This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John J. Lee |
last post by:
I'm trying to change a base class of a big class hierarchy. The
hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class
that defines __getattr__ and __setattr__ that I need to...
|
by: Simon Elliott |
last post by:
I have a class which uses a singleton to output progress messages for
logging or display. It's typically used deep within a hierarchy of
aggregations, inheritances and containers. The singleton...
|
by: William Djaja Tjokroaminata |
last post by:
Hi,
As I am interfacing my code in C++ with a scripting language which is
written in C, I need to store pointers to objects in a class hierarchy:
ParentClass *obj1;
obj1 = new ParentClass...
|
by: ik |
last post by:
Hello All,
Please point me to the right news group if this is not the right one.
I have to store c++ class hierarchy, in some structure. From that
structure, I need to query for the baseclasses....
|
by: Matt |
last post by:
Hello,
I would like to generate what I call an "overall class hierarchy" in
UML automatically derived from my C++ code source.
An example of what I seek:
...
|
by: Mark Broadbent |
last post by:
Consider the following statements
//-------
Item i = Basket.Items; //indexer is used to return instance of
class Item
Basket.Items.Remove(); //method on class item is fired
item i = new...
|
by: Bror Johansson |
last post by:
Hi,
I have a class-hierarchy (fairly deep and fairly wide).
Is there a good and general way to test an instance-object obj for having a
class belonging to a certain "sub-tree" of the hierarchy...
|
by: Jef Driesen |
last post by:
Suppose I have a datastructure (actually it's a graph) with one template
parameter (the property P for each edge and vertex):
struct graph<P>;
struct vertex<P>;
struct edge<P>;
I also have...
|
by: krzysztof.konopko |
last post by:
Hello!
I want to design a class hierarchy with one base abstract class, let's
say CBase. I have a predicate that every object in the class hierarchy
must have a parent object of type from this...
|
by: Gordon |
last post by:
I want to provide a set of static functions in a superclass that work
with class constants defined in a decendant of that class.
Unfortunately I've run into a snag with this idea. Example:
...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |