The interface of the application is designed through Wxformbuilder and can be run.
But the app stays in a running phase, and from a design and maintenance perspective, there are a number of flaws.
In this article, we will combine the Wxformbuilder tool to talk about how to make this application easier to maintain.
This article focuses on a problem: How to peel down the GUI design and business logic design. Wxformbuilder provides a very powerful automatic code generation function, which is the main reason we choose Wxformbuilder. However, after using it, you will find that if the UI is changed slightly after you have designed it through Wxformbuilder, you will have to re-merge the UI section and our custom business logic code.
In this case, the object-oriented thinking, through "class inheritance" can be very easy to avoid the trouble caused by this problem. First Look at:
In the above UML we will design a lookup window (finddialog), which contains two classes: Finddialogbase and Finddialog, and the latter inherits from the former. During the design process, the Finddialogbase class is completely designed by Wxformbuilder and generates code automatically. Finddialog after inheritance, there is an additional requirement in addition to displaying the lookup window:
Ability to record all of the user's search records.
Here is a brief analysis of this requirement:
1, every time the user click Find to do all the time, the user entered the content to record;
2, when the user closes the Search window, or click "Quit" to end the search, the record entries are cured to the hard disk;
3. The next time the user brings up the lookup window, read the last saved entry from the hard disk and initialize it to the drop-down menu in the Find Input box.
From the above analysis, it is natural to see that in subclass Finddialog a variable that holds the user input entry is required, and the value of this variable is loaded and saved on the hard disk at initialization (construction) and exit.
The code to implement class inheritance is as follows:
classFinddialog (finddialogbase):" "Implement the Find Dialog; " " def __init__(self, parent, filename =hist_filename): Finddialogbase.__init__(self, parent)#The history Filenane;Self . Histfilename=filename#The find history;Self . Findhistory= [] #Disable the **find** Button;self.m_btnFind.Enable (False)#Initialize the Find history;Self .__initfindhistory() #Initialize the String Combo List;Self .__initfindcombobox() #Set window focus;Self.m_cmbString.SetFocus ()
By inheriting the class, the UI and the business processing logic are stripped, realizing the understanding of the even. For example, in the process of users, will continue to put forward new requirements, such as:
1, Increase the check box, to specify whether case sensitive;
2, filter the input content;
3, forward search, backward search;
4 、......
The user's needs are constantly changing, and only the UI and the logical solution can be implemented to cope with the changes more calmly.
C + + Wxformbuilder: Implementing the UI and processing logic through class inheritance