Hi all,
We are working on an internal API to create customers and orders in our system using
EJB. I have read in the blueprints about value objects, and I'm all for them when it comes to getting or updating data that can be logically grouped together. For example, instead of getting and setting the customer firstName, lastName and phone, get and set a customer value object with all relevant data in it.
But I am a little worried that some here are taking the value object concept a little too far. Some have proposed designs that have the client API operating only on value objects, and only communicating with a single bean to update or add an entry, passing a value object in as a single parameter. This is done they say for the sake of performance.
This bothers me because the client has no validation whatsoever on the value objects themselves. So the client calls all these set methods, adding data to these objects (which contain other value objects, which they also construct and add data to), and calls a single method like addOrder(OrderValueObject). This is the only time the client is made aware of any business rule violations, since they never talk to any beans directly. This also adds more classes to maintain and worry about when changes are made.
These people here also have all the set methods on thier value objects, which I don't like (and the blueprints advise against). To me, this gives has the potential for giving the client the (wrong) impression that when they call setCustomerPhone() that they have updated the customer's phone number, which they of course have not. The blueprints state that value objects should be immutable, with constructors and get methods only, in order to prevent the client from making this mistake.
Does anyone else use value objects to this extent? Do any of you go out of your way to prevent a client (
servlet,
java app, whatever) from calling any of your beans directly? Maybe I think this is too simple, but what is wrong with a servlet programmer looking up my bean and talking to it?
If you are not familiar with the term value object, it is just a simple class that holds some values so they can be serialized and moved from client to server, grouping related data together, like Address and CreditCardInfo.
Any input is appreciated. Sorry if I have rambled, I'm a little frustrated.
Bill