Musings about this and that

March 12, 2009

Java Pearls: Why not copy the attribute’s value onto itself

Filed under: Java Pearls — ajesse @ 2:47 pm
Tags:

I like it, when values are set into attributes from where they have been fetched. Makes for readable code.

UserBean deputyChange = myTransferObject.getDeputy();
if (deputyChange != null && deputyChange.getUid() != null) {
  if (!checkUserRole(deputyChange.getUid(), FunctionGroups.ROLE_TO_CHECK.getRole())) {
    throw new IllegalArgumentException("Deputy user-id not valid: " + deputyChange.getUid());
  }
  myTransferObject.setDeputy(deputyChange);
  myContext.getMyBean().getMyOtherTransferObject().setAssistanceUserDetail(deputyChange);
}

Apart from the fact that the webapplications user gets a nice looking Exception Message in his browser if he selected the wrong user from a list… It really makes sense to set the originating attribute to the value it delivered just a few lines above…

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.