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


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

Re: DI/wiring

Newsgroups comp.lang.java.programmer
Date 2013-04-23 23:32 -0700
References <DI-wiring-20130418174944@ram.dialup.fu-berlin.de> <MeVbt.370900$Nq4.247520@newsfe21.iad> <conventions-20130424061354@ram.dialup.fu-berlin.de>
Message-ID <f1082fc4-ae00-4b3f-adba-251a2fd15ade@googlegroups.com> (permalink)
Subject Re: DI/wiring
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Stefan Ram wrote:
> Daniel Pitts 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!

It makes perfect sense, assuming you don't reject the convention.
 
>   But I am not a native English speaker. May be I am missing
>   something here.

This really doesn't have anything to do with native English, or really 
English at all except as a basis for technical terminology.

What you are missing, deliberately at a guess, is the convention set
recommended for all serious Java programmers.

Every profession has its argot. The meaning of 'setXyz()' and 'getXyz()' in 
Java is a matter of domain-specific terminology.

Your analysis is utterly correct modeling methods as actions, or messages, 
depending on the methodology by which you describe programs. In a word, 
behaviors. So yes, in that sense you tell the object to accept an argument.

In UML you model behaviors, or methods, below the line below attributes.

In Java, unlike C# and some other languages, there is not a direct 
implementation of attributes, modeled differently from behavioral methods.
One could use elevated-visibility member variables, 'public Xyz xyz;', but 
this practice is decried. Instead, by nearly universal convention in Java, one 
uses specific JavaBean-compliant names for methods that wrap these 
members and provide attribute characteristics.

This convention has been around since the Java equivalent of the Paleolithic Age.
It was established by Sun's attempt to promote JavaBeans. It's the part that really 
stuck, as it turns out Java really needed a good implementation for attributes.
What we got are getters (accessor methods) and setters (mutator methods), so 
named for the conventional 'getXyz()' and 'setXyz()' patterns for naming the 
wrapper methods for the 'xyz' attribute.

... [snip] ...

>> 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?

Aye, therein lies the rub. It is a vocabulary issue.

A setter is a mutator method taking a single argument corresponding to 
a type attribute, named in the JavaBean pattern of 'setXyz(Xyz xyz)' for 
a hypothetical attribute 'xyz' of type 'Xyz'. It is one of a pair of methods 
used to give Java full power to express a type attribute, the other being 
the 'getXyz()' accessor method.

There are advantages to following the convention, not least of which is 
the ability to communicate in full bandwidth with knowledgeable Java 
programmers. Many tools (IDEs, rich-application platforms, etc.) take 
advantage of this convention and other JavaBean conventions to provide 
robust, component-based, rapidly-developed functionality.

It's really not such a bad thing to follow Java conventions. Really it's not.

-- 
Lew

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