Designing a method signature - TechRepublic
General discussion
December 29, 2002 at 08:19 AM
ugo posada

Designing a method signature

by ugo posada . Updated 23 years, 5 months ago

I designed an application a couple of months ago and I came up with the following signature for a method:

void updateSomething(String type, String something)

The kind of update depends on the string value passed in the type parameter, what I remenber vividly is that I bragged a lot because there was the possibility to pass an empty string giving new meaning to the method, for instance, updating all types or whatever. I guess one gains a lot of cohesion because the method itself gives a single entry point to accomplish plenty of different things, but, at what cost. I imagine one has to document the method very strictly to explain every possible use of it, giving a hard time to the programmer for he has to examine the documentation every time he has to use it to prevent misuse.

Would it be better to have different signatures for every type, I mean:

void updatePerson(String a)
void updateCamel(String a)
void updateElf(String a)
void updateGorgeousSpaceLady(String a)

I guess it is more intuitive, but wastes a lot of space. I like to hear your thoughts about it, I would even like to hear if you approach the same problem in a more elegant way, see ya.

This discussion is locked

All Comments