Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!news.glorb.com!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: Sat, 11 Jun 2011 13:04:59 -0500 Date: Sat, 11 Jun 2011 11:04:57 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Class.forName().newInstance() vs new References: <95ho4qFd7cU1@mid.individual.net> In-Reply-To: <95ho4qFd7cU1@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 20 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.199.66 X-Trace: sv3-YHTmQmxD5VcQ3tgLppbRImoDrl4yXl8WzxdiSbDTzVqrrtd+5me1LFPyrNRc4TPOFtDkOfNrNYRGKGt!qfFdFvACmZ0XfuEzGfmIuh1vMqmBv2jPsapaxRaCQfkXIRFAeNVa38+sPOz6AztGUPiZHn0l8v9S!b0LZtxgu4LwvFon5qcJa0FLeqH3uccbsNXHjELj0/BSSxw== 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: 1959 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5210 On 6/11/2011 10:49 AM, Robert Klemme wrote: > On 11.06.2011 19:13, Abu Yahya wrote: ... >> else { // handle unrecognized >> Class k = Class.forName(dbMgrClassName); >> db = (DB) k.newInstance(); >> } ... > Doing if else cascades is certainly the worst thing - not so much > because of the performance but because of the deficiency that you need > to touch the code every time you want to add a new class. With the other > two approaches you do not have to do that. ... As coded, the forName code was left in as a fall-through handler, so it new classes can be handled without touching the code. Of course, that also means it has all the complications of both the if-else approach and the forName approach. Patricia