Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23622

Re: DI/wiring

From Arved Sandstrom <asandstrom2@eastlink.ca>
Newsgroups comp.lang.java.programmer
Subject Re: DI/wiring
References <DI-wiring-20130418174944@ram.dialup.fu-berlin.de> <MeVbt.370900$Nq4.247520@newsfe21.iad> <conventions-20130424061354@ram.dialup.fu-berlin.de>
Message-ID <S5Qdt.24625$yB7.2776@newsfe25.iad> (permalink)
Organization Public Usenet Newsgroup Access
Date 2013-04-24 09:19 -0300

Show all headers | View raw


On 04/24/2013 01:34 AM, Stefan Ram wrote:
> Daniel Pitts <newsgroup.nospam@virtualinfinity.net> writes:
>> Why aren't those simply setters? Must you go against all convention in
>> every possible way?
>
>    I just had to remember that remark, when I read a method
>    name of mine that made me smile myself, it was the name
>
> acceptReportAcceptor
>
>    . Here is some more context:
>
> public void acceptReportAcceptor( final ReportAcceptor reportAcceptor )
> { this.reportAcceptor = reportAcceptor; }
>
>    . But now, honestly, when one sees a hungry man, and gives
>    him some bread and says:
>
>        »Sir, please accept this bread!«
>
>    this sound fine to me, while
>
>        »Sir, please set this bread!«
>
>    sounds strange. In
>
> object.acceptNumber( 2 )
>
>    I tell the object to accept the number, but what is
>
> object.setNumber( 2 )
>
>    supposed to mean? How can the object set the number 2?
>    This makes no sense!
>
>    But I am not a native English speaker. May be I am missing
>    something here.
>
>    Imagine I would have called the reportAcceptor
>    »reportSetter«. This would have made no sense to me! This
>    object is supposed to accept a report, not to set a report!
>    The report is already »set« by the caller, the callee is
>    just asked to kindly consider accepting it!
>
>> Why aren't those simply setters?
>
>    Actually I do not know the definition of »setter« that you
>    take as basis for your question. When do you call something
>    a setter?
>
Others have provided good responses. Here's my take.

You certainly know the getX/setX convention, and you also certainly know 
that this convention is sometimes required by frameworks. So I won't 
belabour that point.

You're already making one valuable point, which is that if getX and setX 
don't sound quite right, that maybe the X is not really a "property" of 
the object being modelled by the Java class.

 From a natural language standpoint, perhaps it would help to translate 
getX and setX to "get value of (my) X" and "set value of (my) X", 
because that's really what the accessor naming shorthand means. If 
phrased this way you'll see that there is a reasonable interpretation of 
what the callee is doing, not the caller. Although the getter sounds 
even better in natural English as "get and provide value of (my) X".

If after this mental translation the natural language meaning of the 
getter/setter is still not sensible, then maybe you really don't have an 
object property.

That's really the OO definition of accessor methods: the operations for 
retrieving or modifying the value of the property of an object. The 
naming conventions do interfere somewhat with the options we've then got 
available for methods that describe behaviour, but they had to call them 
something.

AHS

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: DI/wiring Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-04-18 09:32 -0700
  Re: DI/wiring Lew <lewbloch@gmail.com> - 2013-04-23 23:32 -0700
  Re: DI/wiring Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-04-24 09:44 +0200
  Re: DI/wiring Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-24 09:19 -0300
  Re: DI/wiring Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-04-24 08:40 -0700
    Re: DI/wiring Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-24 13:05 -0300
    Re: DI/wiring Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-04-24 21:14 +0200
  Re: DI/wiring Joerg Meier <joergmmeier@arcor.de> - 2013-04-24 20:13 +0200
    Re: DI/wiring markspace <markspace@nospam.nospam> - 2013-04-24 14:22 -0700

csiph-web