Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.help Subject: Re: Is it sign of bad Object Oriented programming? Date: Sun, 24 Apr 2011 15:21:15 -0400 Organization: albasani.net Lines: 33 Message-ID: References: <87wriklitz.fsf@merciadriluca-station.MERCIADRILUCA> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net XArOtgH9qheKEzPNshphLxieA8HZIAIXvtPKeIBpF4R8hcozDjayJlk8/andrfM0YS4dZX2+qzdKkcHKOvIaGs0zMKxe1GPDRGUqOnzHiBKzS63uFEMZiCnvfCGM6jSh NNTP-Posting-Date: Sun, 24 Apr 2011 19:21:11 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="e90AXwA18+Qol107f3U1h3zMr/cIWDmfV/RVjIBMb+Oq5BdA/0z4N1xNVPra15f0/ylBp+hm3GIKdY98DP2jDoj1ZKT84kfgezSqABeIaoy3+bqnMJXJ217J9wupj7o+"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: Cancel-Lock: sha1:YGS+xUxXt/Am0VvriaTBve2imXI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:641 Eric Sosman wrote: > Merciadri Luca wrote: >> Let us consider a class Class and an object myObj of type Class. Let >> there be a method myMeth defined in the Class class. >> >> Are there some cases where typing e.g. >> == >> myObj.myMeth(myObj) >> == >> is not considered as `bad style?' That is, are there, more generally, >> some situations where passing an instanciated object to a method of >> this object is a good way of achieving something? > boolean arrayHasEqualThing(Thing[] array, Thing thing) { > for (Thing t : array) { > if (t.equals(thing)) // Look here! > return true; > } > return false; > } This differs from the problem statement, which has the argument reference the same instance as that through which the (instance) method is called. The method that you show here is a candidate for 'static' scope as it does not depend on the state of 'this'. In particular, there is no guarantee in this proposal that 't' or 'thing' point to the 'this' instance, nor to the same instance as each other. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg