Mix and match class in C++/MFC
Posted
by
Coder
on Stack Overflow
See other posts from Stack Overflow
or by Coder
Published on 2011-01-03T17:15:10Z
Indexed on
2011/01/03
17:53 UTC
Read the original article
Hit count: 201
I'm trying to re-factor a code base, and there is some common functionality among unrelated classes that I'd love to unite. I would like to add that functionality in common base class, but I'm not sure if it's clean and good approach.
Say I have CMyWnd
class and CMyDialogEx
class, both different, so they cannot inherit from one base class. I want to add a button to both classes and add the message handlers to both classes as well.
So I'd like to do something like this:
CMyWnd : public CWnd, public COnOkBtnFunctionality, public COnCancelBtnFunctionality
CMyDialogEx: public CWnd, public COnOkBtnFunctionality
Where COnOkBtnFunctionality
would define CButton m_buttonOk
, and all the afx_msg
functions it should have. And so on.
Is this approach doable/good? Or are there better patterns I should resort to?
© Stack Overflow or respective owner