Organizing GUI code

后端 未结 3 1140
我寻月下人不归
我寻月下人不归 2021-02-08 12:18

My question has two parts:

  • Does anyone have any tips or references to some documentation on the web about how to write GUI code that is easy to read, write, and

3条回答
  •  礼貌的吻别
    2021-02-08 12:41

    Some guidelines for the first question, from an OO perspective:

    • Break up large classes into smaller ones. Does that panel have a bunch of fairly modular subpanels? Make a smaller class for each subpanel, then have another, higher-level class put them all together.
    • Reduce duplication. Do you have two trees that share functionality? Make a superclass! Are all of your event handlers doing something similar? Create a method that they all call!

    Second question. I see two ways of doing this:

    • Listeners. If many components should respond to a change that occured in one component, have that component fire an event.
    • Global variables. If many components are reading and writing the same data, make it global (however you do that in your chosen language). For extra usefulness, combine the two approaches and let components listen for changes in the global data object.

提交回复
热议问题