Simple Question on View

Topics: CAB & Smart Client Software Factory
Jun 16, 2006 at 11:39 AM
originally posted by: ksunair

Whenever you create a view using GAD, it creates, View, Interface to View and View Presenter.

What are these and why do we need them? Also if we are using MVP model, where do we put all the bussiness logic behind the view. At present I am creating a control that created using depenency injection.

On the side note, if the controller is required why GAD is not creating by default??

Am I introducing something new or am I missing the real MVP pattern created by SC_BAT???

Thanks in advance.
Jun 20, 2006 at 6:44 AM
originally posted by: ksunair

Could someone enlighten me on this question, it is bothering me for a while.
Jun 20, 2006 at 1:09 PM
originally posted by: headlam

The Smart Client Software Factory guidance package has a recipe that supports creating a view-presenter combination. The view is a user control attributed with the SmartPart attribute. The view represents the graphical user interface (i.e., UI) and is the V in MVP. This is where you ad the controls that display information etc. (i.e., grid view, tree controls, labels, etc.). The presenter communicates with the view via an interface that the view implements (logically speaking the presenter defines the interface). The presenter communicates with the view via an interface so you can more easily test the presenter class (independent of a UI framework … i.e., WinForm, etc.) related controls (i.e., the view). This makes unit testing more palatable. The presenter is the P in MVP and is where you would put the logic you are referring to. The presenter is there to serve the view. When the view is created the presenter class will be created via DI. Hope that helps. The MVP pattern is in some someway similar to the MVC pattern. However, the MVP pattern is more suitable for modern IDE. In this case you don’t need a controller for the view since you are using MVP. The module that was created does have a controller class (see the work Item). This controller class is more of an “application controller” on a small scale in this case. I would avoid putting logic here that is meant for the presenter class that serves the view.

Jun 21, 2006 at 7:18 AM
originally posted by: ksunair

Thanks thats clear. Right now I created a controller and put the logic in there, it should be in the presenter correct? 2 questions
1. Where is the right place for putting the logic for button click event etc., I can put the button click event in the view itself and implement the bussiness logic in the presenter and call the presenter method from view. Is it the right approach? Is there an example for this?
2. Can you access the controls from the presenter itself? How can you access them? Is there an example in the help topics??

Thanks again in advance.
Jun 21, 2006 at 11:18 AM
originally posted by: ksunair

Got all figured out, of course with your help. Correct me if I am wrong,

both the presenter and the view get created during the build-up process based on what is in the addview of the work item.

Presenter and view gets each others references through dependency injection (view reference to presenter is through Interface of the view). So when you want to use presenter, use _presenter and call use its internal or public methods.
If presenter wants to use, some methods in view, define the method in the interface of the view and use the method.

Does it sound correct??

Jun 21, 2006 at 2:45 PM
originally posted by: matiaswoloski

You got it quite well.
The V and P are partners who chat in order to get input and write output from/to the UI.

patterns & practices Smart Client Software Factory Team
Jun 22, 2006 at 7:22 AM
originally posted by: ksunair