Don't Assume a Getter is Benign
If (myBean.getDate() != null && ! myBean.getDate().equals( today))
showDate( myBean.getDate());
I have seen methods where the same getter has been called more than twenty times as it was needed in complex business logic. There is more than one problem with this:
- Even if the getter is benign now - meaning that all it does is retrieve package private data, you can't be sure it will remain so. If the call later causes database access or an RMI call it can cause significant response times.
- It makes the code appear far more complex than it actually is, so.
- General readability is lowered.
Date initiationDate = myBean.getDate();
If (initiationDate != null && ! initiationDate.equals( today))
showDate( initiationDate);









0 Comments:
Post a Comment
<< Home