views:

67

answers:

4

Why do people say that business logics should be implemented on the server side code (e.g. EJB) and not on the client application code?

The example that I have in mind is a business object validation on a EJB based architecture. Does it really have to be delegated to the EJB or is it ok to run it on the client before the object is sent to be server to be saved?

+5  A: 

There are two reasons. First, you're likely to have the same business logic for multiple clients, so it makes sense to factor it out to the server. Second, you most likely can't trust the client, which means server validation is essential.

Matthew Flaschen
+7  A: 

Validation can be done client-side in order to save the round-trip to the server. But the server should also perform the same validation. Ideally, you can reuse the same classes on both client and server-side.

Bozho
+3  A: 

Why do people say that business logics should be implemented on the server side code (e.g. EJB) and not on the client application code?

That's something we've learned from client/server (fat clients) architectures. With such architectures, you had to redeploy all the clients to change something and this was just a pain. Server side applications and centralized deployment (with thin or rich clients) don't have this problem and are thus preferred.

The example that I have in mind is a business object validation on a EJB based architecture. Does it really have to be delegated to the EJB or is it ok to run it on the client before the object is sent to be server to be saved?

Validation is something that you must perform on the server side ("don't trust the client") and can also perform on the client side to avoid a round trip. And I'm not even mentioning the case of multiple clients (a GUI, a command line application, a batch, etc).

Pascal Thivent
+1  A: 

Because usually the client code is used to display the information and not really to define what the application does.

Mainly because this gives you flexibility to add other clients without having to do strange tricks ( like copy/paste )

For instance, assume your client is using HTML, later you want to add a new client using json.

If the business rules were on the client, you'll have to copy them to the new client.

Now, don't get confused with validation rules and other. Those have to be placed in the client side too.

OscarRyz