Question on MVC in .NET

P

-pb-

Hi,

We are developing an windows application and decided to use the MVC
design pattern. We decided to use windows application due to varuous
business processes which cannot be implemented in web very easily

Now my problem is very specific.

We have a main screen which shows some data called Main view. We have a
controller calss which holds a reference to the object of Main view and
underlying service. Now we want to save the details entered on the
screen to database, but before adding to database, we show a screen and
allows user to select to save on exiting one or new one and lot of
other stuff.

My questions are
1 - do we required to have a sepearate controller for each view. In our
case, MainController and SaveController or we should have only one
controller i.r. MainController.
2 - If only one controller is used and if that controoler is holding
object reference of Main view, how other view can be handled.
3 - If 2 contoller is used then how to pass the data from Main view to
Save view.

At the moment our project become so complex as v hv to pass the
MainController evertime between view and each view hv has its own
controller.

Any suggestion is appriciated
 
M

Michael Nemtsev

Hello -pb-,

-> We have a main screen which shows some data called Main view. We have
-> a controller calss which holds a reference to the object of Main view
-> and underlying service. Now we want to save the details entered on
-> the screen to database, but before adding to database, we show a
-> screen and allows user to select to save on exiting one or new one
-> and lot of other stuff.
->
-> My questions are
-> 1 - do we required to have a sepearate controller for each view. In
-> our
-> case, MainController and SaveController or we should have only one
-> controller i.r. MainController.

Generally only one controller, but differen views.
Controller handles events from the different views

-> 2 - If only one controller is used and if that controoler is holding
-> object reference of Main view, how other view can be handled.

Controller creates view, so it knows about views and handles its events

-> 3 - If 2 contoller is used then how to pass the data from Main view
-> to Save view.

Noway. Each controller is separates for each view, no way to interact between
them.

-> At the moment our project become so complex as v hv to pass the
-> MainController evertime between view and each view hv has its own
-> controller.

Several solutions to avoid this
- One controller which handles all views (you can use partial classes to
simplify handling the views)
- Combine the View and the Controller. MVC pattern allows this

I recommend you to read article (which I and my mate wrote) about MVC and
MVP patterns:
http://laflour.spaces.live.com/blog/cns!7575E2FFC19135B4!650.entry

I hope it helps you to find your answers and make MVC more clear for you


---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
P

-pb-

Hi,

Thanks for the informaiton.

After looking into your artical, we are actually using MVP more then
MVC (passive or active). Now as per your suggestion to have one
presenter for all different view, we have an interface which represents
each view and if we use only one presenter then all those interface
needs to be implemented by that one presenter which I think will make
thigns worse as now presenter has more then 1 view to handler.

Furthermore, we nned to comunicate between diferent view i.e. we need
to have Save view and Main view and on click of Save button on Save
view it need to save data from main view. Is there any other design
pattern to handle this or is something wrog we are doing may be wrong
design.

Let me know if u need anymore info. I will try to post the code as
well.
 
P

-pb-

Sorry there is some error in my previous reply. I am rectifying it and
rewrting it as follows

0 - We have one business component called BusinessProcess
1 - We have 2 interface IMainView and ISaveVIew
2 - IMainVIew is implemented by frmMainView form
3 - ISaveView is implemented by frmSaveView form
4 - We have one public class called MainPresenter and SavePresenter.
Both of them uses the BusinessProcess compoent to get/save data.
5 - MainPresenter holds the reference to the object of IMainView and
SavePresenter holds the reference to the object of ISaveVIew
6 - Form MainForm shows the data using MainPresenter and form SaveForm
shows the data using SavePresenter
7 - Now when user clicks on Save button the form, it created an object
of the form which implements the ISaveView and shows the form.
8 - Various data is shown on the form frmSaveView using SavePresenter
and BusinessProcess component
9 - On click on OK button on frmSave we want to save the data from
frmMainView.

Now in above context, can yu pls explain a bit more usage of abt
partial class and where it should fit together. At the moment what we
are doing is MainPresenter is passed to frmSave. frmSave uses its
SavePresenter to do various operation and on click it uses the
MainPresenter to calla function Save which then calls the
BusinessPrcess component's function Save.

In my opnion its not so good solution but is there any way out? Is
there any possible design error?

-pb- said:
Hi,

Thanks for the informaiton.

After looking into your artical, we are actually using MVP more then
MVC (passive or active). Now as per your suggestion to have one
presenter for all different view, we have an interface which represents
each view and if we use only one presenter then all those interface
needs to be implemented by that one presenter which I think will make
thigns worse as now presenter has more then 1 view to handler.

Furthermore, we nned to comunicate between diferent view i.e. we need
to have Save view and Main view and on click of Save button on Save
view it need to save data from main view. Is there any other design
pattern to handle this or is something wrog we are doing may be wrong
design.

Let me know if u need anymore info. I will try to post the code as
well.

Michael said:
Hello -pb-,

-> We have a main screen which shows some data called Main view. We have
-> a controller calss which holds a reference to the object of Main view
-> and underlying service. Now we want to save the details entered on
-> the screen to database, but before adding to database, we show a
-> screen and allows user to select to save on exiting one or new one
-> and lot of other stuff.
->
-> My questions are
-> 1 - do we required to have a sepearate controller for each view. In
-> our
-> case, MainController and SaveController or we should have only one
-> controller i.r. MainController.

Generally only one controller, but differen views.
Controller handles events from the different views

-> 2 - If only one controller is used and if that controoler is holding
-> object reference of Main view, how other view can be handled.

Controller creates view, so it knows about views and handles its events

-> 3 - If 2 contoller is used then how to pass the data from Main view
-> to Save view.

Noway. Each controller is separates for each view, no way to interact between
them.

-> At the moment our project become so complex as v hv to pass the
-> MainController evertime between view and each view hv has its own
-> controller.

Several solutions to avoid this
- One controller which handles all views (you can use partial classes to
simplify handling the views)
- Combine the View and the Controller. MVC pattern allows this

I recommend you to read article (which I and my mate wrote) about MVC and
MVP patterns:
http://laflour.spaces.live.com/blog/cns!7575E2FFC19135B4!650.entry

I hope it helps you to find your answers and make MVC more clear for you


---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
M

Michael Nemtsev

Hello -pb-,

Alex, the main author that article will reply u dimistifying you misunderstandings

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

-> Sorry there is some error in my previous reply. I am rectifying it
-> and rewrting it as follows
->
-> 0 - We have one business component called BusinessProcess
-> 1 - We have 2 interface IMainView and ISaveVIew
-> 2 - IMainVIew is implemented by frmMainView form
-> 3 - ISaveView is implemented by frmSaveView form
-> 4 - We have one public class called MainPresenter and SavePresenter.
-> Both of them uses the BusinessProcess compoent to get/save data.
-> 5 - MainPresenter holds the reference to the object of IMainView and
-> SavePresenter holds the reference to the object of ISaveVIew
-> 6 - Form MainForm shows the data using MainPresenter and form
-> SaveForm
-> shows the data using SavePresenter
-> 7 - Now when user clicks on Save button the form, it created an
-> object
-> of the form which implements the ISaveView and shows the form.
-> 8 - Various data is shown on the form frmSaveView using SavePresenter
-> and BusinessProcess component
-> 9 - On click on OK button on frmSave we want to save the data from
-> frmMainView.
-> Now in above context, can yu pls explain a bit more usage of abt
-> partial class and where it should fit together. At the moment what we
-> are doing is MainPresenter is passed to frmSave. frmSave uses its
-> SavePresenter to do various operation and on click it uses the
-> MainPresenter to calla function Save which then calls the
-> BusinessPrcess component's function Save.
->
-> In my opnion its not so good solution but is there any way out? Is
-> there any possible design error?
->
-> -pb- wrote:
->
Hi,

Thanks for the informaiton.

After looking into your artical, we are actually using MVP more then
MVC (passive or active). Now as per your suggestion to have one
presenter for all different view, we have an interface which
represents each view and if we use only one presenter then all those
interface needs to be implemented by that one presenter which I think
will make thigns worse as now presenter has more then 1 view to
handler.

Furthermore, we nned to comunicate between diferent view i.e. we need
to have Save view and Main view and on click of Save button on Save
view it need to save data from main view. Is there any other design
pattern to handle this or is something wrog we are doing may be wrong
design.

Let me know if u need anymore info. I will try to post the code as
well.

Michael said:
Hello -pb-,

-> We have a main screen which shows some data called Main view. We
have
-> a controller calss which holds a reference to the object of Main
view
-> and underlying service. Now we want to save the details entered
on
-> the screen to database, but before adding to database, we show a
-> screen and allows user to select to save on exiting one or new
one
-> and lot of other stuff.
->
-> My questions are
-> 1 - do we required to have a sepearate controller for each view.
In
-> our
-> case, MainController and SaveController or we should have only
one
-> controller i.r. MainController.
Generally only one controller, but differen views. Controller
handles events from the different views

-> 2 - If only one controller is used and if that controoler is
holding -> object reference of Main view, how other view can be
handled.

Controller creates view, so it knows about views and handles its
events

-> 3 - If 2 contoller is used then how to pass the data from Main
view -> to Save view.

Noway. Each controller is separates for each view, no way to
interact between them.

-> At the moment our project become so complex as v hv to pass the
-> MainController evertime between view and each view hv has its own
-> controller.

Several solutions to avoid this
- One controller which handles all views (you can use partial
classes to
simplify handling the views)
- Combine the View and the Controller. MVC pattern allows this
I recommend you to read article (which I and my mate wrote) about
MVC and MVP patterns:
http://laflour.spaces.live.com/blog/cns!7575E2FFC19135B4!650.entry

I hope it helps you to find your answers and make MVC more clear for
you

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo
 
A

alex.ms

Use another schema:

0 - You have the business component called BusinessProcess and THIS
component IS model and used for interaction between Presenter(s) and
your Views.
....
6 - Form MainForm shows the data (interacting with BusinessProcess as
model) using MainPresenter and form SaveForm shows the data using
SavePresenter (we have only single one model - BusinessProcess and
all your business components)

So, when you click "Save" on the Main form:
7 - the form raises the event in MainPresenter and MainPresenter
stores the MainForm's data into the model
8p1 - MainPresenter asks SavePresenter to create the SaveForm.
8p2 - SavePresenter fills SaveForm with data from the model (data was
stored on the step 7), and shows the SaveForm
9 - On click the OK button on frmSave we raise the event in
SavePresenter which handle form data.
There are 2 cases:
a) You save all your data in the model and mark them "temporary".
When u need to save them your SavePresenter change the status of your
data.
b) You send data from the MainPresenter to model and then use this data
to show SaveForm. Then Again send SaveForm data to model to perform
real saving

Kind regards,
Alex Meleta [http://ameleta.spaces.msn.com]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top