views:

110

answers:

1

Should a Presentation Layer be split into presenting and receiving objects Or single objects that handle data in both directions?

+2  A: 

The presentation layer should be sitting behind interfaces that handle both presenting and receiving. The main reason is that if you had two interfaces, one for presenting and the other receiving it is possible, in theory to wind up with two different object assigned to each causing strangeness in testing.

However if your interface is developing into dozens of method you may want to step back and look at dividing it into smaller units then aggregate them. Not necessarily based on receiving and presenting but more logical divisions of your presentation UI.

For example you could have a IPresentationUI with two variables one is an interface of IPresentationDisplay and the other of IPresentationControl. The only registration routine you have will accept a IPresentationUI object. The class implementing the Prensentation layer would be implementing three interfaces IPresentationUI, IPresentationControl, and IPresentationDisplay.

RS Conley
so the same object that presents data would receive new user input and then the object would be passed to domain? The Domain decides what to extract from the presentation object? Are there any security risks in this?
zsharp
The general idea is that the interface is implemented by a form or a object representing the webpage and is a thin shell passing events to a UI Object, and receiving instructions on how to draw/setup the presentation. The UI Object responsible to take that raw input and executing commands that modify the domain. This include doing any security that is necessary. Only when the command is executed is the domain touched. So if the security checks fail don't execute the command.
RS Conley
The advantage of this approach is that putting your user interaction behind a interface you gain several advantages. First you abstract much of the specific UI api away. So web standards change, Form Frameworks change but as long as the new classes implement the interface the rest of your software can continue operating. Second testing becomes easier as you can have mock objects implement the UI interfaces. Third You documented through the interface exactly how your software interacts with a given UI.
RS Conley