Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!zen.net.uk!dedekind.zen.co.uk!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: A question about some long java code that has getters/setters Date: Mon, 25 Jul 2011 16:50:55 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <1672e2f1-a963-4fcf-b651-41b69432c9d7@p29g2000pre.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 25 Jul 2011 23:50:57 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="1498"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AtTIip2WFV1R3St29tatEhaOWKwZyP58=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Cancel-Lock: sha1:+QSzV6+8iGq11Nt5j3mcH4Tl6jM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6556 On 7/25/2011 1:27 PM, Patrick May wrote: > It encourages a style of programming where > objects have too much knowledge about each other. This is an interesting idea. However, I think it might be short sighted, or at least incomplete. For example, I've just been working on a project which involves sending commands over a network. There are up to four parameters for all commands, and it might be better style to perhaps only create some number of constructors which only allow valid combinations of these four parameters. However, I went instead with the "natural" mutator approach. First, supplying a constructor or method for each possible combination would result in a large number of constructors or methods, vs. the simplicity of just four mutators. Second the internal state of the object is not so hard to grasp that the mutators are hard to use. It's pretty easy and basic to set the parameters you want and then ship the command across the network. And last, large numbers of arguments can be difficult to work with. Users don't always remember the correct order, and swaping two parameters inadvertently is a hazard. Harder to do that with just a single parameter, and easier to spot an error in a code review. So, yes I think you have a point that mutators shouldn't be used in every case. But I think there's a rather large numbers of cases where they do work, and are best practice.