Re: A question about some long java code that has getters/setters
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.?
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.
When their contract (documentation) does not contain such
references, encapsulation is not broken.