Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 24 Apr 2011 14:54:36 -0500 Date: Sun, 24 Apr 2011 12:54:32 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.java.help Subject: Re: Is it sign of bad Object Oriented programming? References: <87wriklitz.fsf@merciadriluca-station.MERCIADRILUCA> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2IednYrMyuph4inQnZ2dnUVZ_gWdnZ2d@earthlink.com> Lines: 44 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-MRkXC+aFrTthvizySMaj5W9JptsWUoOCDeY4JhY5OIoy+4vOcwuuJjXvxsc5dzyUzh2tRm0AeRU4ncI!e686ya9hva23hLqOLHyPkh8WdvR/GVNtVbOiVlv641wzBt0rWKrlKhY2zTjOYd4fzPB1zLJv+i4M!miEV9hksWKJFeBskmbtriPpr65oUGum4m3hYMNKb2mg= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2673 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:642 On 4/24/2011 12:21 PM, 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. >>> == >>> 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? Patricia