I believe in OO, but not to the point where inappropriate designs/implementations should be used just to be "OO Compliant".
So, how to deal with the Serlvet/EJB/DataContainer layered architecture:
This approach has appeal; the DataContainers are clear in what they do and it's very easy to know where data comes from.
Aside from not being OO, this leads to unclear Business Layer classes that can be hard to name and hard to organize.
Even if we were trying to be more "OO" (e.g. putting some of these methods in the DataConatiners), some of these operations operate on more than one set of data.
How do you keep your Business Layer from getting confusingly procedural, but without polluting your DataContainers with business logic?
class UserServlet {
handleRequest() {
String id = request.get("id");
String name = request.get("name");
if (UserBizLayer.updateUserName(id,name))
response.setStatus(OK);
else
response.setStatus(BAD_REQUEST);
}
}
class UseBizLayer {
updateUserName(String id, String name) {
long key = toLong(id);
user = userDAO.find(key);
if user == null
return false;
if (!validateUserName(name))
return false;
user.setName(name);
userDAO.update(user);
return true;
}
validateUserName(String name) {
// do some validations and return
}
}
class User {
long key;
String name;
String email;
// imagine getters/setters here
}
validateUserName
on the user, since it only operates on a name; I guess it could go into another class, but then we have another procedural "uti" type classI realize this example isn't that bad, but imagine 10 DataContainers and 20 BizLayer objects with several methods each. Imagine that some of those operations aren't "centered" on a particular data container.
How do we keep this from being a procedural mess?
So I'll address my thoughts on this in a few bullet points: