-
I have multiple classes that have different behaviors and I want the behavior for building the objects of those classes in separate builder classes. In Smalltalk, I could have a temporary variable called, say, builder, that would hold the builder object for the class being built, but due to the strong tying of C++ this cannot be done. Everything I have tried gets messy. Any ideas? Thanks.
-
-
@JonB said in Strong typing problem:
I don't see any Qt polymorphic classes? :)
QWidgetis a big one.Overriding a function or class method is an example of "doing polymorphism". Qt has lots of those.
-
@JonB said in Strong typing problem:
I don't see any Qt polymorphic classes? :)
QWidgetis a big one.Overriding a function or class method is an example of "doing polymorphism". Qt has lots of those.
-
@J.Hilk said in Strong typing problem:
@JKSH
I'm pretty sure, @JonB was being cheeky ;-)Sometime hard to tell in written form 😉

-
@J-Hilk , @JKSH
Actually, I wasn't!Bearing in mind that I'm Python not C++ so I don't see the sources, all I get to see for Qt is the documentation, where the declarations of each class show what it's derived from. Now, apart from base classes like
QWidgetorQObject, which may or may not be polymorphic I can't tell, I haven't seen a single class which lists anything other than one class from which it is derived? -
@J-Hilk , @JKSH
Actually, I wasn't!Bearing in mind that I'm Python not C++ so I don't see the sources, all I get to see for Qt is the documentation, where the declarations of each class show what it's derived from. Now, apart from base classes like
QWidgetorQObject, which may or may not be polymorphic I can't tell, I haven't seen a single class which lists anything other than one class from which it is derived?@JonB The methods tagged with
virtualare polymorphic. for example: QAbstractItemModel::data and QWidget::event -
@JonB The methods tagged with
virtualare polymorphic. for example: QAbstractItemModel::data and QWidget::event@VRonin
Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? So you would write something like:class One(Class_Two, Class_Three, ...) { }(remember I'm not C++, and my beloved C# although it allows
interfaces only allows a class to be derived from one other class). That is what I was saying I do not see a lot of in Qt.I know what
virtualis, but what is polymorphic about it?? -
@VRonin
Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? So you would write something like:class One(Class_Two, Class_Three, ...) { }(remember I'm not C++, and my beloved C# although it allows
interfaces only allows a class to be derived from one other class). That is what I was saying I do not see a lot of in Qt.I know what
virtualis, but what is polymorphic about it??@JonB said in Strong typing problem:
@VRonin
Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? ..... That is what I was saying I do not see a lot of in Qt.That's multiple inheritance. See https://doc.qt.io/qt-5/qwidget.html :
Inherits: QObject and QPaintDeviceI know what
virtualis, but what is polymorphic about it??https://stackoverflow.com/questions/2835793/how-does-polymorphism-work-in-python
-
@JonB said in Strong typing problem:
@VRonin
Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? ..... That is what I was saying I do not see a lot of in Qt.That's multiple inheritance. See https://doc.qt.io/qt-5/qwidget.html :
Inherits: QObject and QPaintDeviceI know what
virtualis, but what is polymorphic about it??https://stackoverflow.com/questions/2835793/how-does-polymorphism-work-in-python
@JKSH
Ohhhhhhhhhhhhhhhhhh!!!I really thought the "poly" was the "multiple" in "multiple inheritance"...! I went to a talk about C++ multiple inheritance many years ago, and I really thought the guy used the "poly" word, either I'm mixing up or the lecture wasn't about what I thought it was :)
OK, everything I said was about "multiple inheritance" not "polymorphism", so sorry. Yes, I see now
QWidgetis exactly what I had in mind, but there are not many other Qt classes which are multiple inheritors. -
@JKSH
Ohhhhhhhhhhhhhhhhhh!!!I really thought the "poly" was the "multiple" in "multiple inheritance"...! I went to a talk about C++ multiple inheritance many years ago, and I really thought the guy used the "poly" word, either I'm mixing up or the lecture wasn't about what I thought it was :)
OK, everything I said was about "multiple inheritance" not "polymorphism", so sorry. Yes, I see now
QWidgetis exactly what I had in mind, but there are not many other Qt classes which are multiple inheritors.@JonB said in Strong typing problem:
but there are not many other Qt classes which
Inheriting multiple classes from the same tree is frowned upon, and most of the time for good reason, because you'd have to do a virtual inheritance and ... well ... it gets complicated. Inheriting multiple classes is otherwise fine. Especially inheiriting classes that were made to be inherited - like those containing pure virtual functions -
QIODevice,QAbstractView,QAbstractItemModelto name a few.Basically anything that has a virtual destructor is supposed to be inherited at some point ... and
QObjecthas one. -
@JonB said in Strong typing problem:
but there are not many other Qt classes which
Inheriting multiple classes from the same tree is frowned upon, and most of the time for good reason, because you'd have to do a virtual inheritance and ... well ... it gets complicated. Inheriting multiple classes is otherwise fine. Especially inheiriting classes that were made to be inherited - like those containing pure virtual functions -
QIODevice,QAbstractView,QAbstractItemModelto name a few.Basically anything that has a virtual destructor is supposed to be inherited at some point ... and
QObjecthas one.C# allows a class to inherit from only one class --- so it can only be one "kind of object" --- but you can add as many
interfaces as you like to the inheritance. Aninterfaceis effectively a class with just a bunch ofpure virtualfunctions, and nothing else (no variables). Neat, huh? -
C# allows a class to inherit from only one class --- so it can only be one "kind of object" --- but you can add as many
interfaces as you like to the inheritance. Aninterfaceis effectively a class with just a bunch ofpure virtualfunctions, and nothing else (no variables). Neat, huh?@JonB said in Strong typing problem:
An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?
C# is similar to Java in that regard. And yeah, we call that interface in C++ too - an abstract class with no implementations.
But then I also like the fact that if my farm animal is both a horse and a transportation device it can be both with C++, and not pretend that my transportation device has a horse ... or think of 100 reasons to say why a horse cannot be also a transportation device, thus needing to implement the transportation device's specifics for each horse, car, bicycle and helicopter. Neat, huh?
PS.
You're probably not aware of my beloved saying for this particular topic: C++ ain't Java. -
@JonB said in Strong typing problem:
An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?
C# is similar to Java in that regard. And yeah, we call that interface in C++ too - an abstract class with no implementations.
But then I also like the fact that if my farm animal is both a horse and a transportation device it can be both with C++, and not pretend that my transportation device has a horse ... or think of 100 reasons to say why a horse cannot be also a transportation device, thus needing to implement the transportation device's specifics for each horse, car, bicycle and helicopter. Neat, huh?
PS.
You're probably not aware of my beloved saying for this particular topic: C++ ain't Java.And yeah, we call that interface in C++ too - an abstract class with no implementations.
Yeah, but you don't actually have an
interfacekeyword :)if my farm animal is both a horse and a transportation device it can be both with C++
It isn't. It's a horse-animal, which happens to implement a transportation device
interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :) -
And yeah, we call that interface in C++ too - an abstract class with no implementations.
Yeah, but you don't actually have an
interfacekeyword :)if my farm animal is both a horse and a transportation device it can be both with C++
It isn't. It's a horse-animal, which happens to implement a transportation device
interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :)@JonB said in Strong typing problem:
Yeah, but you don't actually have an interface keyword :)
Nope, we don't. But that's only because we like to write more with less typing ... efficiency you see ... ;)
It isn't. It's a horse-animal, which happens to implement a transportation device interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :)
Heheh, and I thought it's an animal that happens to have aggregated transportation device features ... damn, that's the franken-horse ...!