Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what would be the super strategy pattern?

I have a user interface with multiple sections (say, 9 UI sections in a 3x3 grid). 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.

like image 443
Martin08 Avatar asked Feb 03 '26 21:02

Martin08


1 Answers

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.

like image 169
Mark Seemann Avatar answered Feb 05 '26 14:02

Mark Seemann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!