Friday, May 8, 2009

Know why ...

When doing things as they have always been done, it is important to sometimes say 'STOP!' and try to figure out why you should do it like that. If encountered this a couple of times this week.

When adding a comment on an overridden method, eclipse automagically enters {@inheritDoc} and that's it. Made sense to me but I had no idea what the things does. Well in this case, the {@inheritDoc} and what the default behavior is when there is no comment is the same. Thus for keeping you're code clean instead of cluttering it with unuseful stuff, you could just ommit it. You can still use it if you want to add to the original comment because {@inheritDoc} will copy over the original comment at that place. Something like this:
/**
* {@inheritDoc} and does a lot of other useful stuff.
*/
public void overriddenMethod()
Generating getters and setters for domain objects was the second thing I do most of the time. It seems like a good idea and makes all information easily accessible. On the other hand it makes things so simple that you don't think about encapsulation anymore and do things in the wrong place. A better approach is to wait to create the getters and setters until you really need them and at that time think how you could still keep the data encapsulated.

0 reacties:

 
The opinions expressed in this blog are those of Jeroen Wyseur and may not reflect the opinion of his employer or any customer of said employer.