|
|
Re: Designing a function
|
Posted: Dec 30, 2002 5:35 AM
|
|
> 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.
Hi, in fact what you're trying to do is replacing the setXXX javabeans standard with an updateXXX. this gonna break the introspection feature, do you really want to do that?. but if you think that your class code is getting very huge because of the number of getter/setter methods maybe you'll better try to do some design work using a composition pattern for example. for more informations have a look on the java.beans package I think it will be very helpful about this subject.
|
|