Re: Inherintance or Variable
A class which encapsulates a button plus a lisbox plus an edit box and so on, has no practical sense.
So, just use simple inheritance when dealing with windows.
// see my signature. ;)
Re: Inherintance or Variable
Quote:
Originally Posted by ovidiucucu
A class which encapsulates a button plus a lisbox plus an edit box and so on, has no practical sense.
example...
Code:
class cMainWindow
{
cWindow Window;
cButton SaveButton;
cButton CloseButton;
cListBox DataListbox;
public:
cMainWindow() : Window(), SaveButton( Window ), CloseButton( Window ), DataListbox( Window )
{
Window.Show();
}
}
That makes sense to me. I think you meant:
A class which inherits a button plus a lisbox plus an edit box and so on has no practical sense.
Of course one does use encapsulation with inheritance by the use of access specifiers.
Quote:
Originally Posted by NLscotty
The problem I've is
should I make a variable of Button or
should I make button public for the window class like this:
Code:
Code:
class Window : public base, public button { // stuff } class myclass : public Window { // stuff }
else I've to do to in myclass this,
Button * button1;
I believe you think that if you inherit multiple types( button, listbox ), you're generating a class which utilizes that type as an object and that is wrong. You effectively made your new class behave as if it were all of them combined. Now consider trying to inherit another button :|. You will see that your class already behaves like a button and it can't behave like a button again.
You are misusing inheritance in a way to express your idea that is incorrect down to the fundamentals of c++, so how can you include 2 buttons with inheritance? Obviously you can't. You are mixing up inheritance with objects. With objects, you can have multiple buttons.
NLscotty, please understand that creating your own wrapper takes extensive understanding in not only c++, but win32. Let's not forget about proper design. This can take years for someone who is just starting at your fundamental level.
Quote:
If I included them all in Window class it will be huge. Should I do this or not?
The more you inherit, the bigger your class will get. Right now I wouldn't worry about false optimization nor would I support your current design. I would recommend you look at the code above.
Quote:
Also does the compiler leave out the code which the class do not need. For instance when myclass only the use the button class from Window, the rest got inculded to?
Usually the compiler will remove functions that aren't used.
The best ideal you can try is:
1. learn the difference from inheritance and objects
2. learn c++ first with oop design in mind
3. learn from other widgets and how to improve on them. for ex, how does mfc pipe messages? Does it support multithreading?
4. learn win32 separately
Again a window is not a button and a listbox and a combobox nor should it be implemented like a button and a listbox and a combobox.
Also multiple inheritance can be a good thing if used correctly.
Re: Inherintance or Variable
Quote:
Originally Posted by
Joeman
I think you meant:
A class which inherits a button plus a lisbox plus an edit box and so on has no practical sense.
Just was formally talking in other words.
Quote:
Originally Posted by
Joeman
Also multiple inheritance can be a good thing if used correctly.
Not in the discussed case.
Here is scratching with the foot and violates the KISS principle. ;)