开发者

what would be the super strategy pattern?

I have a user interface with multiple sections (say, 9 UI sections in a 3x3 grid开发者_Python百科). The content of a section (i.e. its UI components) are instantiated differently at runtime according to some conditions. So I guess I would use Strategy pattern for each section. Besides simple conditions, the states of instantiated sections are also used as entrance condition to instantiate or re-instantiate other sections.

For example, if condition X is true, section (1,1) is instantiated to a text box and a submit button. If X is false, S(1,1) will contain a table and a submit button. When the button is clicked, if S(1,1) has a table, S(1,2) will contain a form which details the selected record in the table of S(1,1). If S(1,1) is instantiated with a text box when the button is clicked, S(1,2) will contain a table. And so it goes; the interaction gets complex.

What design pattern can help me coordinate this complex interaction and stay away from a messy nested ifs code? Thank you.


It's best if you can keep each component decoupled from each other using pure events - that would be the Observer pattern. Otherwise Mediator comes to mind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜