Hello, guys, I am programming a GUI for an application, a cd container to insert cd, and currently I am not very clear and I think I need some help to clarify my understanding about object oriented design.
so, first, I use observer pattern to build abstract Model and View classes and also the concrete models(cd container) and concrete views(cd container view). Then I start to use the wxwidget framework to design and graphical appearance or layout (CDContainerWidget, from wxPanel) for the cd container and other gui controls MainFrame(from wxFrame), etc..
so now I have three classes: CDContainerModel
(cd container), CDContainerView
(the class for observer pattern), and CDContainerWidget
(the gui controls).
then I become not that clear about what I should do with the CDContainerView
and CDContainerWidget
?
I think CDContainerWidget and CDContainerView both need CDContainerModel. I think about four approaches, but do not know which one is approriate:
1). associate CDContainerWidget into CDContainerView as a member variable, then put the CDContainerView into the Main Frame as a member variable.
class CDContainerView:
def __init__:
self.gui=CDContainerWidget
class MainFrame:
def __init__:
CDContainerView
2). CDContainerView subclass CDContainerWidget:
class CDContainerView(CDContainerWidget):
class MainFrame:
def __init__:
CDContainerView
3). CDContainerWidget subclass CDContainerView:
class CDContainerWidget(CDContainerView):
class MainFrame:
def __init__:
CDContainerWidget
4). instead of using CDContainerWidget and CDContainerView, use only a single class CDContainerBig which subclass the abstract class View and wxPanel
class CDContainerBig(View, wxPanel)
My question is what is the right solution? I have read the wiki page of MVC pattern, but I do not really understand its descrption and do not know how and also wonder if it is approriate to apply it to my problem.
well, I put some additional comments. originally, when i start to design to program, I did not think much and just choose, 2) approach. but now, I think 3) is good. since it is reasonable to put widget in widget(CDContainerWidget into MainFrame). but I am not really sure. Also it seems with observer pattern, the three classes are twisted and awkard. And sometimes, it appears to me that these 4 maybe are the same, just who includes who, or who sends messages to who. well, I think I really need clarification on this point.
Also, I am in favour of 3) because of a practical point.The CDContainerWidget actually contains several subwidget components (button, input box, etc.) and if we change something like set new values via a subcomponent widget, then for 1), we need CDContainerWidget to be aware of CDContainerView, to let CDContainerView to notify other views. for 2) even worse, CDContainerWidget has to be aware of its childen CDContainerView. for 3) CDContainerWidget itself is CDContainerView, so quite reasonable. for 4) well, easy but no logic separation. this is my own thought, do not know if it is correct.
Thanks!!