Reputation: 986
I'm writing a big webforms application and I'm using the MVP pattern. The application is a application for a loan and the user needs to answer a lot of questions. My problem is that on one page there can be up to about 15-20 questions and their visability are dependant on previous answers.
So each time an user answers a question "A" the View might call SetVisabilityB() in the presenter which handles whether to show or hide question "B". So far so good, but the answer in question "B" shows/hides question "C", and when the user changes his/hers opinion on question "A" the view have to call both SetVisabilityB() and SetVisabilityC()... I find this a bit messy, since I now have places where I need to call 5-6 different SetVisability methods for one question..
Should I use a "global" SetVisability method that updates the visability for all the questions for each answer or is there a better way to solve this?
Upvotes: 0
Views: 73
Reputation: 943
My main problem with your approach is that your view contains the business logic for when to show and hide questions. The view should be as dumb as possible and it should be your presenter making these decisions.
I would have the view signalling to the presenter that a question has been answered and pass the question number. The presenter can hide or show the questions as needed. This could take the form of a case statement, or if things are getting stupidly complicated then you could switch to using a state machine.
Upvotes: 1