Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Abu Yahya Newsgroups: comp.lang.java.programmer Subject: Re: Class.forName().newInstance() vs new Date: Sat, 11 Jun 2011 23:52:34 +0530 Organization: Aioe.org NNTP Server Lines: 26 Message-ID: References: <95ho4qFd7cU1@mid.individual.net> NNTP-Posting-Host: VXdcwsc5kgxY1YKHPVeYyQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5215 On 6/11/2011 11:34 PM, Patricia Shanahan wrote: > 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. That's right. > Of course, that > also means it has all the complications of both the if-else approach and > the forName approach. The intent was to get the best of both worlds, but I agree it's made it less easy to understand.