/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Reserving the prefix set and get in setPro~
Fra : news.cybercity.dk


Dato : 26-03-02 14:29

Hi everyone.

I would like to restrict the use the prefixes get and set to getPropertyName
and setPropertyName as used in the beans standard of methods only getting or
setting a value.

When I get or set a value in a method and at the same time execute some
extra code I would like to use anoter prefix for my method.

I would like to have an advise what to use instead.

Example:
getMyMethod() could be retrieveMyMethod(). setMymethod(...) could be
insertMyMethod(...).

My native language is not english so I would like an advise from someone
with good knowledge of the english language.

My lexicon give a lot of options:

get , fetch, read, retrieve, from, out, ...

set , add, save, put, stor, change, modify, update, stuff, stick, push,
place, deposit, import, input, place, in, enter, ...

Hope for a good discussion.

Villy Ib Jørgensen

mailto:villy.joergensen@lindhard.com





 
 
Peter Lind (27-03-2002)
Kommentar
Fra : Peter Lind


Dato : 27-03-02 21:08

<villy.joergensen@lindhard.com> wrote:
> Hi everyone.
>
> I would like to restrict the use the prefixes get and set to
getPropertyName
> and setPropertyName as used in the beans standard of methods only getting
or
> setting a value.

Very good idea - always use the standard methodnames when applicable...

> When I get or set a value in a method and at the same time execute some
> extra code I would like to use anoter prefix for my method.
>
> I would like to have an advise what to use instead.

Well, I'd have to say that it depends largely on what you will be doing in
the method, and who will use it.
I, for one, don't like APIs with lots of getXXX, retrieveXXX, loadXXX and
fetchXXX, because you can never be entirely sure of what the author meant,
when naming the method...

So, a method that just returns a value, like the day of the month, simply
call it getDayOfMonth() - if however the method does something more, like
updates the birthday calendar or something, it really should be called
getDayOfMonthAndUpdateBirthDayCalendar()...
This is a stupid example, but since I haven't the slightest idea as to your
application, or method implementations, it is a bit hard to give more
specific help.

If you could elaborate a bit on the exact function of the methods, you would
probably receive more and better advice - or maybe even find the solution by
yourself.

And for a further, deeper discussion about method and variable-naming, refer
to Steve McConnell: Code Complete
(http://www.amazon.co.uk/exec/obidos/ASIN/1556154844/026-6508173-9220446)


/Peter Lind
-der iøvrigt også kan dansk....



Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408523
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste