Newbie question: combining Window and Component


#1

Following some of the example code, I have 2 classes for each window in my test app I’m using to learn JUCE. For example:

[color=#0000FF] class MyWindow : public DialogWindow …
class MyComponent : public Component …[/color]

In the constructor for [color=#0040FF]MyWindow[/color], I then use: [color=#0000FF]setContentOwned( new MyComponent, false );[/color]

My question: is there something obvious I missed that would prevent MyWindow from being both the window and the component at the same time? Wouldn’t that let me cut in half the number of classes I write? I’m thinking if Foo inherits from both DialogWindow and Component, I would then put this in the constructor:

[color=#0000FF] setContentNonOwned( this, false );[/color]


#2

Noooo!! You should NEVER look for ways to use more inheritance!! Always try to do the opposite and avoid inheritance unless there’s genuinely no other way to do what you need to.

Having more classes is generally not a bad thing. And using many small, well-encapsulated, loosely-coupled classes is vastly better than having one huge bloated monster class that inherits everything.