Three-layer arcitecture

T

Tony Johansson

Hello!

What is your opinion about the presentation layer(PL) and the design. Assume
I create a presentation layer using Windows form and then for some reason I
want to change to WPF instead: I mean that if all validation is located in
the Business layer it would be enough just to switch to WPF. But if I had
validation in the PL I had to implement these in the PL that uses WPF.

Give me a comment about this.

//Tony
 
A

Arne Vajhøj

What is your opinion about the presentation layer(PL) and the design. Assume
I create a presentation layer using Windows form and then for some reason I
want to change to WPF instead: I mean that if all validation is located in
the Business layer it would be enough just to switch to WPF. But if I had
validation in the PL I had to implement these in the PL that uses WPF.

Give me a comment about this.

Much of the validation belong in the business layer.

But there are two reasons why you want to move some of
the validation to the presentation layer.

First of all you don't want your business layer to
take only strings as arguments. That would be horrible
type unsafe and the business layer could be called from
something other than a presentation layer. So you want to
convert to the real data types. This is somewhat the
reflection of that this type of validation is not really
business logic. Try ask an accountant if you can have
a negative amount of cash and he will tell you that you can't.
Try ask an accountant whether you can have "XYZ" amount
of cash and he will not know what you are talking about.

The other aspect is usability. If the presentation layer
knows about the valid formats for the data you may be
able to provide a better UI than if everything had to go
down to the business layer for validation. You can
let the user pick an enum via a combo box. You can
present phone number entering in a certain format - for
US (nnn)nnn-nnnn. Etc.. For web UI's you can even do
some validation client side in JavaScript to avoid
roundtrips to the server.

Arne
 
T

Tony Johansson

Arne Vajhøj said:
Much of the validation belong in the business layer.

But there are two reasons why you want to move some of
the validation to the presentation layer.

First of all you don't want your business layer to
take only strings as arguments. That would be horrible
type unsafe and the business layer could be called from
something other than a presentation layer. So you want to
convert to the real data types. This is somewhat the
reflection of that this type of validation is not really
business logic. Try ask an accountant if you can have
a negative amount of cash and he will tell you that you can't.
Try ask an accountant whether you can have "XYZ" amount
of cash and he will not know what you are talking about.

The other aspect is usability. If the presentation layer
knows about the valid formats for the data you may be
able to provide a better UI than if everything had to go
down to the business layer for validation. You can
let the user pick an enum via a combo box. You can
present phone number entering in a certain format - for
US (nnn)nnn-nnnn. Etc.. For web UI's you can even do
some validation client side in JavaScript to avoid
roundtrips to the server.

Arne

You mentioned Web UI and as you said the validation is done on the Client by
using JavaScript if the browser support that but you should also have a
check on the server to make sure that all data is correct before for example
saving to db.

So I implement check in PL to make sure that the account is not negative and
numeric and so on but do I then have to
make a second check in BL to really be sure that all data is correct in the
same way that Webb does ?

//Tony
 
A

Arne Vajhøj

You mentioned Web UI and as you said the validation is done on the Client by
using JavaScript if the browser support that but you should also have a
check on the server to make sure that all data is correct before for example
saving to db.

Yes. Client side check for convenience and server side check for
security.

Some web frameworks allow you to add one check and the framework
will automatically do it both client and server side.
So I implement check in PL to make sure that the account is not negative and
numeric and so on but do I then have to
make a second check in BL to really be sure that all data is correct in the
same way that Webb does ?

If the PL call the BL with an uint, then there is little need
for testing for numeric and non negative.

:)

Arne
 

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