Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
Flaggers, this isn't really on topic for Code Review, and it's perfectly fine here. –  Yannis Rizos Mar 30 '12 at 13:40
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
Yeah. I would go with the dot syntax. It's more intuitive. –  kadaj Mar 30 '12 at 6:36
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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