473,395 Members | 1,401 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,395 software developers and data experts.

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 3430
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.learn.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 WindowingService 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
WindowingService 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
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...
3
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. ...
14
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...
22
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...
8
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,...
6
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...
60
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...
5
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
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...
3
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:...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
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...
0
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,...
0
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...

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.