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 17:26:20 -0400 Organization: albasani.net Lines: 58 Message-ID: References: <87wriklitz.fsf@merciadriluca-station.MERCIADRILUCA> <2IednYrMyuph4inQnZ2dnUVZ_gWdnZ2d@earthlink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net 53I+U17SRzrJph4Nd9NhhXPV8AOdAwInt4ttYKCZTE4tkuJWB2p4+iQSgwDh69/Pi3S6gmlgznco8SpH4erqYX6DU7FWMl1/jGjaD1u0xNEUpnrm364tfiGFZTZKpJx+ NNTP-Posting-Date: Sun, 24 Apr 2011 21:26:20 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="Df7UkTwSJ8cgC+HhjRV4ZgjqA9eMCpspI+fifV5xj3+fvXedlgVh+4MnuUmXtx86/1SY7201nJ2XXvb9H7WU5osOKWjCyJgBRyb6wJeijjkuVtjv/28RrfsYeffrlUmk"; 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: <2IednYrMyuph4inQnZ2dnUVZ_gWdnZ2d@earthlink.com> Cancel-Lock: sha1:NOmtiUW/1xpiXFY0KI5L1At20ws= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:643 Patricia Shanahan wrote: > Lew wrote: >> 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. [sic] >>>> == >>>> 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. > Consider an arithmetic type Widget, like BigInteger, with a multiply > method that returns the Widget representing the product of this and a > Widget argument. > > Now write Widget's square method: > > public Widget square() { > return multiply(this); > } > > Is that what is being discussed? Of course, the OP will have to clarify this, but the example given was: myObj.myMeth(myObj) This represents a client, not 'this', calling a method that takes the reference itself as an argument. Stefan Ram gave a motivating example: System.out.println( System.out ); Your example doesn't fit the proffered pattern. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg