1

I have wrote a small method in a program to do one thing my method looks like this:

public static void removeExpiredAssignments(Module module){
    module.removeExpiredAssignments();
}

So the method is called like:

removeExpiredAssignments(module);

When the desired operation could be done by saying:

module.removeExpiredAssignments(); 

Which is easy to understand from the code point of view?

1
  • Flaggers, this isn't really on topic for Code Review, and it's perfectly fine here. – yannis Mar 30 '12 at 13:40
2

It depends what you're trying to do. Calling the method on the module directly implies that the module is required and directly effected by the action. Calling the method that takes in a module implies that the module may or may not be needed in order to carry out the action, and that it may or may not directly effect the state of the module.

1
  • Yeah. I would go with the dot syntax. It's more intuitive. – user4626 Mar 30 '12 at 6:36
2

This ties in with Jeremy's answer, but I'd say it's a question of whose responsibility it is to execute the method. Is the module where the knowledge of how to perform this belongs? If so, it should be the module that executes the method on itself. If the knowledge of how to do this belongs elsewhere, the method should be on that other object/class and take the module as its argument.

1

Java still feels alien to me but I would expect to find the module.functionCall(); syntax; it really is "the java way". I was brought up in C (almost 20 years ago) and the function declaration feels old fashioned even to me, so that's saying something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.