Link to home
Create AccountLog in
Avatar of ias1021
ias1021

asked on

view model relation

Hi All,

  I am planning to implement MVP for desktop application. I have 20 screens in my application. Should I maintain separate model for each view? Do I need to create all views and models while application initialization time? What is the best practice to maintain views and corresponding models?

 Thanks in advance.

Best regards,
ias.
ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ias1021
ias1021

ASKER

Hi TommySzalapski, Sara,

     Thank you for your response.

     I have included business logic in Model.

     for ex:  I got input from user On screen 1(push button click). view forwarded information to model through presenter. Model got updated latest data with the help of business logic. Presenter refreshed the view. This is fine if only one screen.

           main()
           {
                       IView* pV = new View();
                       Presenter*p = new Presenter(pV); // this is fine for single screen.
           }

                 In case of two screens, which is the best way to switch from Screen 1 to Screen 2? ( in presenter or in view)
                  Here screen2 requires screen1 model information. How to pass?

         Thanks in advance.

Best regards,
ias.
if you have one model and two views (screens) you normally would show both screens and let the user decide which has the focus. if a button-click on the first screen retrieves new data to the model which was shown in the second screen, the model (presenter) would open the new screen and make it presenting the data. the focus would go to the second screen if the user could do any actions there.

generally, the views get their data from model and not the model is pushing data to the screens.

Sara
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ias1021

ASKER

Hi TommySzalapski, Sara,

     Your answer is very close to my expected solution Tommy.

     I may ask simple question. But, it is blocking me. Please suggest best book or article for MVP for desktop application.

MVP in Desktop application:
------------------------------------

1. V1 -- P1 -- M1
2. V2 -- P2 -- M2
3. V3 -- P3 -- M3

Here V1, V2, and V3 are completely different. So, all are having different Models.

When V1 got success notification from M1 through P1, then only V2 should be visible.
When V2 got success notification from M2 through P2, then only V3 should be visible.
V3 is last view. exit application.

In C++, I can create V1, then create "P1 with V1 as an argument" in main() function. Now, I need to change the view to V2.  

My doubt is: Where do I need to create V2 and "P2 with V2"?

Thanks in advance.

Best regards,
ias.