Multiple inheritance

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Multiple inheritance

Post by N64vSNES »

GyroVorbis wrote:Eh, it's just a different style of OO design.

Saying C++ allowing multiple inheritance is "poor design" is really stupid. There are many extremely useful applications for it. The downsides are that it makes things more complex, and there are ambiguities.

Java, C#, and these "single inheritance, multiple interface" OO languages simply favor a different style. They want you to strictly enforce a difference between interface and implementation.

edit: Especially now that I've spent such a considerable amount of time developing with QT... there are some SERIOUSLY fucking convenient/powerful (though questionable) things you can do with multiple inheritance, some casting, and signals and slots.

Here's a snippit from some toolkit code:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
Poor design? I'll let you decide. The amount of things that QT now handles for me and the thousands of lines of code I can save with this kind of abuse and some clever casting is so fucking worth it.
Daaaaaaaaaaaaaaaaaaaaaaaaaaaaayum.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Multiple inheritance

Post by Ginto8 »

GyroVorbis wrote:Eh, it's just a different style of OO design.

Saying C++ allowing multiple inheritance is "poor design" is really stupid. There are many extremely useful applications for it. The downsides are that it makes things more complex, and there are ambiguities.

Java, C#, and these "single inheritance, multiple interface" OO languages simply favor a different style. They want you to strictly enforce a difference between interface and implementation.

edit: Especially now that I've spent such a considerable amount of time developing with QT... there are some SERIOUSLY fucking convenient/powerful (though questionable) things you can do with multiple inheritance, some casting, and signals and slots.

Here's a snippit from some toolkit code:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
Poor design? I'll let you decide. The amount of things that QT now handles for me and the thousands of lines of code I can save with this kind of abuse and some clever casting is so fucking worth it.
Touche. I guess when you have a good framework it's ok ;) Tho it must be admitted that this is the exception, not the norm, and there are a lot of cases where it just makes things messier rather than easier.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
adikid89
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 94
Joined: Tue Apr 27, 2010 6:59 am
Current Project: small tiny-mini projects
Favorite Gaming Platforms: PC I guess...
Programming Language of Choice: c++

Re: Multiple inheritance

Post by adikid89 »

GyroVorbis wrote:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
*confused* ... so... entities are entire widgets? Why :D ? And what's with the private inheriting of the AssetManager? I'm just confused :( ... care to shed some light on that line of code pls? I can't tell what's going on... and I'm pretty curious, as I've never really encountered a useful application of multiple inheritance.
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Multiple inheritance

Post by dandymcgee »

adikid89 wrote:
GyroVorbis wrote:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
*confused* ... so... entities are entire widgets? Why :D ? And what's with the private inheriting of the AssetManager? I'm just confused :( ... care to shed some light on that line of code pls? I can't tell what's going on... and I'm pretty curious, as I've never really encountered a useful application of multiple inheritance.
My understanding is that Entity inherits QWidget because entities are widgets in the ES Toolkit. I believe they inherit from AssetManager in order to have a pointer to the manager. I'll let Falco confirm and/or explain what is actually going on in more detail.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Multiple inheritance

Post by Falco Girgis »

dandymcgee wrote:
adikid89 wrote:
GyroVorbis wrote:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
*confused* ... so... entities are entire widgets? Why :D ? And what's with the private inheriting of the AssetManager? I'm just confused :( ... care to shed some light on that line of code pls? I can't tell what's going on... and I'm pretty curious, as I've never really encountered a useful application of multiple inheritance.
My understanding is that Entity inherits QWidget because entities are widgets in the ES Toolkit. I believe they inherit from AssetManager in order to have a pointer to the manager. I'll let Falco confirm and/or explain what is actually going on in more detail.
Yes, and yes. The QGraphicsRectItem is the physically rendered entity.
CC Ricers
Chaos Rift Regular
Chaos Rift Regular
Posts: 120
Joined: Sat Jan 24, 2009 1:36 am
Location: Chicago, IL

Re: Multiple inheritance

Post by CC Ricers »

Boy that's nuts, even though I can understand how that's implemented. I usually put pointers to managers within the class i.e. composition. At one point I had a base entity class have a manager as a friend class, but the manager would probably have too much power over editing the entities.
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Multiple inheritance

Post by GroundUpEngine »

N64vSNES wrote:
GyroVorbis wrote:Eh, it's just a different style of OO design.

Saying C++ allowing multiple inheritance is "poor design" is really stupid. There are many extremely useful applications for it. The downsides are that it makes things more complex, and there are ambiguities.

Java, C#, and these "single inheritance, multiple interface" OO languages simply favor a different style. They want you to strictly enforce a difference between interface and implementation.

edit: Especially now that I've spent such a considerable amount of time developing with QT... there are some SERIOUSLY fucking convenient/powerful (though questionable) things you can do with multiple inheritance, some casting, and signals and slots.

Here's a snippit from some toolkit code:

Code: Select all

class Entity: public QWidget, public TreeNode, public QGraphicsRectItem, AssetManager {
Poor design? I'll let you decide. The amount of things that QT now handles for me and the thousands of lines of code I can save with this kind of abuse and some clever casting is so fucking worth it.
Daaaaaaaaaaaaaaaaaaaaaaaaaaaaayum.
My sentiments exactly! :lol:
Post Reply