tags:

views:

54

answers:

1

Why use a Presentation class instead of an Interface when filtering model properties for submission to View?

+2  A: 

link textI think you are asking the following:

When passing a sub-set of properties to a view, in order to limit the scope-of-knowledge, there are a number of options. Of those, one involves copying the desired properties from the model to an intermediate object (a "presentation class" or a "data-transfer object") and another involves having the model implement an interface and then passing that interface to the view.

Why would you use the former as opposed to the latter?

My answer would be that sometimes you don't have access to the model in order to make it implement that interface. Other times you don't want to pollute your model with unecessary interfaces, for instance you can theoretically have a different interface for every view and that starts adding up.

A hybrid alternative would be to use the adapter pattern to create a class that wraps your model, implements the interface, and delegates the interface calls to your model.

There is no option that's really better than the rest, it all depends on your situation and your "style."

Talljoe
dont understand the last part'adapter pattern'
zsharp
http://www.c2.com/cgi/wiki?AdapterPatternThe adapter pattern allows you to treat a class that doesn't support an interface as if it did by "adapting" it, usually by hiding it within a wrapper that does implement the interface.
Talljoe