471,319 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Practical Benefits of MVC or MVP Patterns

Okay, I just finally figured out the Model View Presenter pattern as
presented by Martin Fowler
(http://www.martinfowler.com/eaaDev/M...resenter.html). I even got a
small model of it working in a Windows Forms app I created from scratch.
Pretty cool how the form is sitting there and gets populated from the
Presenter - and the Form is pretty dumb (i.e., it really has no clue where
it's getting populated from.).

I understand that creating a "dumb" UI layer (per MVP and similar patterns)
has the benefit of allowing us to have multiple forms that all get populated
from the same Presenter. Great. What if I have no intention of ever doing
that (i.e., I have good reason to think I'll never have multiple screens
presenting the same model/data; or I'll likely never be providing both a Web
UI and Windows or Mobile UI). Should I still implement MVP or some other
means of separating the UI (Form) from the underlying data?

Please understand that I already know the answer is likely "yes, of course
you should separate it all out."

But what I would really appreciate are some specific benefits of doing such
separation and concrete examples if possible (reasons beyond the theoretical
"if you ever need to it will all be ready to go.").

Thanks for your time and consideration.

-Jeff

Feb 16 '06 #1
5 9352
Hi Jeff,
no example here but the nice benefit of this pattern is that because your
UI is mainly dumb and the bulk of your code lives inside the controller and
model it makes your code easier to unit test. Because the controllers are
just classes they can be unit tested just like any other class, the more
code you have in the GUI the more you have to test through the GUI which is
difficult, you either have to do it by hand or use some kind of script
generator like Rational Robot, both of which are tedious for regression
testing.

If you are not unit testing your code though then you will obviously not
get the benefit from this. We do this at the place where I work, so it is
not just a theory but I have seen real benefits. On of the first pieces of
code I had to work on all the logic in the GUI and it was virtually
impossible to automate the testing.

My 2 cents :-)

Mark
http://www.markdawson.org
--
http://www.markdawson.org
"Jeff S" wrote:
Okay, I just finally figured out the Model View Presenter pattern as
presented by Martin Fowler
(http://www.martinfowler.com/eaaDev/M...resenter.html). I even got a
small model of it working in a Windows Forms app I created from scratch.
Pretty cool how the form is sitting there and gets populated from the
Presenter - and the Form is pretty dumb (i.e., it really has no clue where
it's getting populated from.).

I understand that creating a "dumb" UI layer (per MVP and similar patterns)
has the benefit of allowing us to have multiple forms that all get populated
from the same Presenter. Great. What if I have no intention of ever doing
that (i.e., I have good reason to think I'll never have multiple screens
presenting the same model/data; or I'll likely never be providing both a Web
UI and Windows or Mobile UI). Should I still implement MVP or some other
means of separating the UI (Form) from the underlying data?

Please understand that I already know the answer is likely "yes, of course
you should separate it all out."

But what I would really appreciate are some specific benefits of doing such
separation and concrete examples if possible (reasons beyond the theoretical
"if you ever need to it will all be ready to go.").

Thanks for your time and consideration.

-Jeff

Feb 16 '06 #2
Hi Jeffs,

Generally this kind of stuff requires more work for the conception of the
control, but give it more flexibility or tweakability shall I say.
So if it is just for 1 end user screen, don't bother.
The only time I found usefull to have a "presenter" was for my custom
textview in C#. all text layout / drawing / etc... is handled in the
DocumenUI class. That way I could reuse the layout/etc code for a credit
control, a PrintDocument, etc...

For simple, no brainer or very unique (i.e. not likely to be reused) drawing
task, this is a tad overkill.....
--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
"Jeff S" <A@B.COM> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
Okay, I just finally figured out the Model View Presenter pattern as
presented by Martin Fowler
(http://www.martinfowler.com/eaaDev/M...resenter.html). I even got a
small model of it working in a Windows Forms app I created from scratch.
Pretty cool how the form is sitting there and gets populated from the
Presenter - and the Form is pretty dumb (i.e., it really has no clue where
it's getting populated from.).

I understand that creating a "dumb" UI layer (per MVP and similar
patterns) has the benefit of allowing us to have multiple forms that all
get populated from the same Presenter. Great. What if I have no intention
of ever doing that (i.e., I have good reason to think I'll never have
multiple screens presenting the same model/data; or I'll likely never be
providing both a Web UI and Windows or Mobile UI). Should I still
implement MVP or some other means of separating the UI (Form) from the
underlying data?

Please understand that I already know the answer is likely "yes, of course
you should separate it all out."

But what I would really appreciate are some specific benefits of doing
such separation and concrete examples if possible (reasons beyond the
theoretical "if you ever need to it will all be ready to go.").

Thanks for your time and consideration.

-Jeff

Feb 16 '06 #3
"Jeff S" <A@B.COM> a écrit dans le message de news:
uf**************@TK2MSFTNGP15.phx.gbl...

| Okay, I just finally figured out the Model View Presenter pattern as
| presented by Martin Fowler

This article doesn't really talk about the "proper" MVP pattern; it seems to
be a slightly more sophisticated MVC pattern.

I have written a complete MVP pattern for Delphi and you can see the
articles on my site : www.carterconsulting.org.uk

| I understand that creating a "dumb" UI layer (per MVP and similar
patterns)
| has the benefit of allowing us to have multiple forms that all get
populated
| from the same Presenter. Great. What if I have no intention of ever doing
| that (i.e., I have good reason to think I'll never have multiple screens
| presenting the same model/data; or I'll likely never be providing both a
Web
| UI and Windows or Mobile UI). Should I still implement MVP or some other
| means of separating the UI (Form) from the underlying data?

Whether you use MVC/P or any other pattern, it really does help your sanity
and the future maintainability of your code.

| Please understand that I already know the answer is likely "yes, of course
| you should separate it all out."

See, I told you so :-))

| But what I would really appreciate are some specific benefits of doing
such
| separation and concrete examples if possible (reasons beyond the
theoretical
| "if you ever need to it will all be ready to go.").

Let me know if my articles help.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Feb 16 '06 #4
Hi Jeff

You could also look at this from the other direction. By keeping the
presentation separate, it doesn't just allow you to add another viewer to
your data. It also allows you to reuse your presenter, since anything that
complies with the interface can be presented in the same way, so you can
have a generic viewer for all your data.

HTH

Charles
"Jeff S" <A@B.COM> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
Okay, I just finally figured out the Model View Presenter pattern as
presented by Martin Fowler
(http://www.martinfowler.com/eaaDev/M...resenter.html). I even got a
small model of it working in a Windows Forms app I created from scratch.
Pretty cool how the form is sitting there and gets populated from the
Presenter - and the Form is pretty dumb (i.e., it really has no clue where
it's getting populated from.).

I understand that creating a "dumb" UI layer (per MVP and similar
patterns) has the benefit of allowing us to have multiple forms that all
get populated from the same Presenter. Great. What if I have no intention
of ever doing that (i.e., I have good reason to think I'll never have
multiple screens presenting the same model/data; or I'll likely never be
providing both a Web UI and Windows or Mobile UI). Should I still
implement MVP or some other means of separating the UI (Form) from the
underlying data?

Please understand that I already know the answer is likely "yes, of course
you should separate it all out."

But what I would really appreciate are some specific benefits of doing
such separation and concrete examples if possible (reasons beyond the
theoretical "if you ever need to it will all be ready to go.").

Thanks for your time and consideration.

-Jeff

Feb 16 '06 #5
I totally agree with Mark.

I would also add:

* It is easier to understand when maintaining it because the roles are
divided up better.
* I seem to remember a refactoring tool that made pulling interfaces out of
classes trivial but I can't remember where I saw it (not in VS2005 express)
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
Hi Jeff,
no example here but the nice benefit of this pattern is that because your
UI is mainly dumb and the bulk of your code lives inside the controller
and
model it makes your code easier to unit test. Because the controllers are
just classes they can be unit tested just like any other class, the more
code you have in the GUI the more you have to test through the GUI which
is
difficult, you either have to do it by hand or use some kind of script
generator like Rational Robot, both of which are tedious for regression
testing.

If you are not unit testing your code though then you will obviously not
get the benefit from this. We do this at the place where I work, so it is
not just a theory but I have seen real benefits. On of the first pieces
of
code I had to work on all the logic in the GUI and it was virtually
impossible to automate the testing.

My 2 cents :-)

Mark
http://www.markdawson.org
--
http://www.markdawson.org
"Jeff S" wrote:
Okay, I just finally figured out the Model View Presenter pattern as
presented by Martin Fowler
(http://www.martinfowler.com/eaaDev/M...resenter.html). I even got
a
small model of it working in a Windows Forms app I created from scratch.
Pretty cool how the form is sitting there and gets populated from the
Presenter - and the Form is pretty dumb (i.e., it really has no clue
where
it's getting populated from.).

I understand that creating a "dumb" UI layer (per MVP and similar
patterns)
has the benefit of allowing us to have multiple forms that all get
populated
from the same Presenter. Great. What if I have no intention of ever doing
that (i.e., I have good reason to think I'll never have multiple screens
presenting the same model/data; or I'll likely never be providing both a
Web
UI and Windows or Mobile UI). Should I still implement MVP or some other
means of separating the UI (Form) from the underlying data?

Please understand that I already know the answer is likely "yes, of
course
you should separate it all out."

But what I would really appreciate are some specific benefits of doing
such
separation and concrete examples if possible (reasons beyond the
theoretical
"if you ever need to it will all be ready to go.").

Thanks for your time and consideration.

-Jeff

Feb 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Design Pattern Catalog | last post: by
1 post views Thread by Jay | last post: by
1 post views Thread by Josh28 | last post: by
13 posts views Thread by John Salerno | last post: by
4 posts views Thread by myhotline | last post: by
12 posts views Thread by Jeff | last post: by
7 posts views Thread by =?Utf-8?B?bWF2cmlja18xMDE=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.