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


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

Re: A question about some long java code that has getters/setters

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.java.programmer
Subject Re: A question about some long java code that has getters/setters
Date Tue, 26 Jul 2011 11:56:55 -0700
Organization A noiseless patient Spider
Lines 69
Message-ID <at2u2712qceiq70etcqa9ed4jjc8dftgvd@4ax.com> (permalink)
References <d94f5902-8b2e-484f-8095-9ce034e916d4@t8g2000prm.googlegroups.com> <1672e2f1-a963-4fcf-b651-41b69432c9d7@p29g2000pre.googlegroups.com> <m21uxehzrj.fsf@softwarematters.org> <j0kvh1$1eq$1@dont-email.me> <Getters-and-Setters-20110726023724@ram.dialup.fu-berlin.de> <hq5s27hjit5limeqt7eef01l8r9539p0ff@4ax.com> <setter-20110726111404@ram.dialup.fu-berlin.de> <vcvt27l0b8c9vqdobhfqhudivq8i8mesjl@4ax.com> <setter-20110726201927@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 8bit
Injection-Info mx04.eternal-september.org; posting-host="7Qrvczazr82YckO5XW8Vtw"; logging-data="1651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9JG1Qlp5izM4R40AFut1gkVzElRqcjys="
X-Newsreader Forte Agent 4.2/32.1118
Cancel-Lock sha1:HMIJC1EEKMeO/a0XnQ8jalc3EqY=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6591

Show key headers only | View raw


On 26 Jul 2011 18:20:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
wrote:

>Gene Wirchenko <genew@ocis.net> writes:
>>>>What is wrong with something like:
>>>>FilePrinter r=new FilePrinter();
>>>>// General Options
>>>>r.SetPrinter("\\Boojum");
>>>>r.SetCopies(1);
>>>>r.SetDoubleSided(true);
>>>Before I can answer this, I need to know, whether there are
>>>setters in the code above. How do you define »setter«? Is a
>>>»setter« any one-argument method, whose name begins with »Set«?
>>In my example, yes.  In general, no.
>
>  There is nothing wrong with one-argument methods whose
>  name begins with »Set« (except that common Java naming
>  style is to use lower-case method names).
>
>>>(To apply my own definition, I would need to see the
>>>documentation of a method, to judge whether it is a »setter«.)
>>Are you going by whether the setter uncritically sets the value
>>or whether it checks the value?
>
>  According to
>
>http://c2.com/cgi/wiki?AccessorsAreEvil
>
>      »accessors are methods that let you read and write the
>      value of an instance variable of an object«.
>
>  My personal definition is similar:
>
>      »An accessor is any method whose contract contains a
>      reference to an instance variable.«

     Then, the answer is no.  However, the contract for such a method
of mine would have reference to the concept that the instance variable
embodies.  I might write the contract for .SetCopies() as:

     .SetCopies() takes one parameter, an integer which is the number
of copies of the file to be printed that will be made when .Print() is
called (assuming sufficient valid printing parameters have been set).
The number of copies must be non-negative.

     If I am reading you correctly, for the above, the answer is no,
but if I change the contract to refer to the instance variable, say
.NumCopies, then it would be a setter.  This distinction strikes me as
rather less than useful.  "So, is it a setter?"  "I can not tell.  I
have not read the contract."

>  Since I do not know whether your methods set the value of an
>  instance variable, I do not know, whether they are »setters«
>  in the sense of my definition. I would need to be able to
>  read their contract (documentation) to learn about this.

     Read my example contract above.  It does not mention an instance
variable, but any reasonable implementation that I am likely to do
would use one.

>  When their contract (documentation) does not contain such
>  references, encapsulation is not broken.

     They set something.  Whether it is an instance variable or not is
irrelevant to their use.

Sincerely,

Gene Wirchenko

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


Thread

A question about some long java code that has getters/setters Chad <cdalten@gmail.com> - 2011-07-22 16:12 -0700
  Re: A question about some long java code that has getters/setters Arne Vajhøj <arne@vajhoej.dk> - 2011-07-22 19:28 -0400
  Re: A question about some long java code that has getters/setters Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-07-22 23:31 +0000
  Re: A question about some long java code that has getters/setters markspace <-@.> - 2011-07-22 16:51 -0700
  Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-23 09:02 -0700
    Re: A question about some long java code that has getters/setters blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-23 17:41 +0000
      Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-23 11:42 -0700
      Re: A question about some long java code that has getters/setters Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 17:59 -0400
        Re: A question about some long java code that has getters/setters Steve Sobol <sjsobol@JustThe.net> - 2011-07-23 23:39 -0700
          Re: A question about some long java code that has getters/setters blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-25 19:44 +0000
          Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 09:03 -0700
    Re: A question about some long java code that has getters/setters Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 19:26 -0400
      Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 09:00 -0700
    Re: A question about some long java code that has getters/setters Patrick May <patrick@softwarematters.org> - 2011-07-25 16:27 -0400
      Re: A question about some long java code that has getters/setters markspace <-@.> - 2011-07-25 15:14 -0700
      Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-25 15:56 -0700
        Re: A question about some long java code that has getters/setters Patricia Shanahan <pats@acm.org> - 2011-07-25 17:00 -0700
          Re: A question about some long java code that has getters/setters Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-25 21:17 -0400
      Re: A question about some long java code that has getters/setters markspace <-@.> - 2011-07-25 16:50 -0700
        Re: A question about some long java code that has getters/setters Gene Wirchenko <genew@ocis.net> - 2011-07-25 18:30 -0700
          Re: A question about some long java code that has getters/setters Patricia Shanahan <pats@acm.org> - 2011-07-25 18:41 -0700
          Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 09:05 -0700
          Re: A question about some long java code that has getters/setters Gene Wirchenko <genew@ocis.net> - 2011-07-26 10:48 -0700
            Re: A question about some long java code that has getters/setters Gene Wirchenko <genew@ocis.net> - 2011-07-26 11:56 -0700
              Re: A question about some long java code that has getters/setters Patricia Shanahan <pats@acm.org> - 2011-07-26 13:34 -0700
                Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 14:21 -0700
            Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 14:20 -0700
        Re: A question about some long java code that has getters/setters Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-25 21:35 -0400
        Re: A question about some long java code that has getters/setters Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-07-26 06:59 -0300
    Re: A question about some long java code that has getters/setters Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2011-07-26 12:19 +0300
      Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-26 09:08 -0700
        Re: A question about some long java code that has getters/setters Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2011-07-27 15:56 +0300
          Re: A question about some long java code that has getters/setters lewbloch <lewbloch@gmail.com> - 2011-07-27 14:14 -0700

csiph-web