In Microsoft, such as VB and. netProgramIn the early stages of employee growth, they generally start with the UI drag and drop. However, programmers who first knew the UI suffered the biggest loss on the UI. In view of the system'sCodeSometimes such code appears. When the drop-down selection box changes, execute the database search method. When a node of a tree is selected, you need to find the bound object from its tag. After finding the bound object, you need to determine whether a check box is selected. Then, if you select what to do, else does what. If no node is selected, a large number of UI states need to be determined. The logic code for status determination is followed by the logic code for status change.
Every time I see code similar to the above, I have a headache. At the beginning, when I saw such code, I would not hesitate to modify it and tell the people who wrote the code how to write it. However, there were too many such code, because all the code was not taken by the master, and developers who found it slowly seemed to have such a process. If they did not have enough talent, if you do not make any special effort, the progress will be slow, and the time spent at this stage will be relatively long. Because I have had such a stage myself, but it is time to go to school. I can only say a lot about my graduation work, but it is not good in many places.
How can I organize the UI Layer? I have summarized two points:
First, you need to use custom controls and components. Each dialog box is composed of some controls and UI components. Each UI control is a component of the dialog box. Therefore, to ensure the reusability of these components, you need to "more" Define User-Defined controls and UI components.
Second, treat the UI class as a common class. The first point of design principles is the single responsibility of the class. This principle may be noticed when writing common classes, but it may not be the case when writing the UI. The concepts of encapsulation, inheritance, polymorphism, and single responsibility are all forgotten. For example, in the UI of a role drop-down box, there may be methods for displaying the list of all roles and external methods for displaying the list of roles, obtain the currently selected role and set the currently selected role object. The role object is passed in. Some events can use the events of the combox itself (this is mainly for convenience), but the functions and methods to be used by these external systems must be defined and implemented from the UI perspective.
As mentioned above, I think the most important way is that developers must understand the UI class as common classes, abide by the object-oriented design principles, and have object-oriented features. Only in this way can the UI Layer write is simple, stable, and flexible.