473,699 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheritance problem


i have a problem with my classes

i have a base class that defines the interface for a window ( abstract
class )
in a render device i have implemented the class for either Direct3D or
OpenGL
on the other hand i would implement the interface also for windows and
linux
my problem is now that the class WindowsWindow would inherit from the basic
window interface
but in runtime it must use either D3D or OGL window as base class( based on
the current render device )

so my class hierarchy would look like this

class window
{
/* data/interface here */
};

class windowGL : public window
{
};

class windowD3D : public window
{
};

class windowWindows : public window
{
};

the above hierarchy would work, but on runtime i need the window functions
of the windowWindows class for D3D or OGL based on the render device
( if it is a GL render device i would need the windowGL as base class,
otherwise windowD3D )

how can such a poblem solved?
Jul 19 '05 #1
3 3474
Nico Massi wrote:

i have a problem with my classes

i have a base class that defines the interface for a window ( abstract
class )
in a render device i have implemented the class for either Direct3D or
OpenGL
on the other hand i would implement the interface also for windows and
linux
my problem is now that the class WindowsWindow would inherit from the
basic window interface
but in runtime it must use either D3D or OGL window as base class( based
on the current render device )

so my class hierarchy would look like this

class window
{
/* data/interface here */
};

class windowGL : public window
{
};

class windowD3D : public window
{
};

class windowWindows : public window
{
};

the above hierarchy would work, but on runtime i need the window
functions of the windowWindows class for D3D or OGL based on the render
device
( if it is a GL render device i would need the windowGL as base class,
otherwise windowD3D )

how can such a poblem solved?


The issue can be resolved by abstracting as much of the common methods
into a generic class and only use the generic functionality.

There is no reason for inheritance since you will never have more
than one window type in a program. Factor this issue out of the
compiler and into the build system. Create a header file that
declares the class. Let the builder tool include the module
that has the definitions depending on the target platform.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #2
Nico Massi wrote:
i have a problem with my classes

i have a base class that defines the interface for a window ( abstract
class )
in a render device i have implemented the class for either Direct3D or
OpenGL
on the other hand i would implement the interface also for windows and
linux
my problem is now that the class WindowsWindow would inherit from the
basic window interface
but in runtime it must use either D3D or OGL window as base class(
based on the current render device ) [SNIP] the above hierarchy would work, but on runtime i need the window
functions of the windowWindows class for D3D or OGL based on the
render device ( if it is a GL render device i would need the windowGL
as base class, otherwise windowD3D )

how can such a poblem solved?


If you can separate OpenGL/D3D from Windows/Linux, I would suggest using the
Bridge pattern or something similar. If you cannot... I have no idea.

You could create a 3DService abstract class and a WindowingServic e abstract
class. Your final classes could use the services of those two, via a
pointer or reference. Those two could also access each other, but that
would introduce the chicken-egg problem. So if the concrete 3DService and
WindowingServic e should access each other, they have to do it via a 3rd
class.

Try not to use inhertiance, thrive for containment. Also - in your case
that seems to be possible - those things which would never change runtime
could be created using interface-equivalence instead of polimorphism.
Meaning that the classes would provide the same interface (same public
functions) but not inheriting from any common (abstract) base.

--
WW aka Attila
Jul 19 '05 #3
Nico Massi wrote:
<snip>

I don't mean to be rude, but I skip messages that don't bother to use
punctuation. If you want an answer to a question, it helps to make sure
the question can be understood, and easily read.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4

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

Similar topics

2
4376
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
3
2467
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. My problem is that I have a /third/ class, CCommand, which derives from both IControl and ICommandmaster... The error message says (Weird.....)
14
12913
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
22
23362
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
8
2206
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods, A1+X2, A2+X1 and A2+X2: interface A class A1 implements A
6
2094
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself so, cannot be called a WebForm itself, the child pages will implement forms). I created a Master.aspx page and removed all HTML from it, added some code to the .aspx.vb file to add controls to my page. Then I created a Child.aspx and changed the...
60
4909
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
5
2751
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
5
3510
by: a | last post by:
Hi, I have an oop inheritance graph problem. What is the difference betweent the following 2 inheritance graph? How does the C++ solve the naming conflict problem for multiple inheritance problem? Thanks A / \
3
2899
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table: tlkpColor (PK) tlkpColorID
0
9178
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
8885
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6534
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
5875
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
4376
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
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
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
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
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.