Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 53917 invoked from network); 13 Jul 2007 21:19:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Jul 2007 21:19:10 -0000 Received: (qmail 89987 invoked by uid 500); 13 Jul 2007 21:19:11 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 89730 invoked by uid 500); 13 Jul 2007 21:19:10 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 89721 invoked by uid 99); 13 Jul 2007 21:19:10 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jul 2007 14:19:10 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of t.p.ellison@gmail.com designates 66.249.92.171 as permitted sender) Received: from [66.249.92.171] (HELO ug-out-1314.google.com) (66.249.92.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jul 2007 14:19:06 -0700 Received: by ug-out-1314.google.com with SMTP id o2so648556uge for ; Fri, 13 Jul 2007 14:18:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; b=A2x+krW3Z2d/KRpkAS26UuwQ82NWrdcwYEu6hMPEebuy4LOv/mgYHgc+/YyjUyEKiXWkupalOZBoFLT3tVOOsIKRm/mYjUoUKuFbjNpagA2h7/83Fd7SQeBLbkZPgPFoenMrG8GHrz3l4Z14IGVHav0LIPc+lZPFdTTlif56GwI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; b=jv6Xq6I/A1NNRhV9U6sbsgEu6Js8W4byRVWuDsOFv759aygoEDVwAPpp+JpVTQ+JgDoghO9uRBqyVXOKGtFm0vKJs6ELk7oh5BzfdyjJanHQUNGtWhuNeBxGjgJGAex2NmW1xev79AE8PN8PmG+gcpT5ahNd2YnsDDiI2Wpu0zM= Received: by 10.67.88.17 with SMTP id q17mr2281068ugl.1184361524628; Fri, 13 Jul 2007 14:18:44 -0700 (PDT) Received: from ?192.168.0.2? ( [86.111.176.100]) by mx.google.com with ESMTP id y34sm53327383iky.2007.07.13.14.18.43 (version=SSLv3 cipher=RC4-MD5); Fri, 13 Jul 2007 14:18:43 -0700 (PDT) Message-ID: <4697EC2D.9000205@gmail.com> Date: Fri, 13 Jul 2007 22:18:37 +0100 From: Tim Ellison User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: dev@harmony.apache.org Subject: Re: [classlib][beans] Code seems duplicate for primitive persistence delegate References: <473c46620707112012j34a77b7cldf5f28864700a867@mail.gmail.com> <2c9597b90707120213w220e527au58b9a676b977c9eb@mail.gmail.com> <473c46620707122006l1bfcb981k6431c9228a25ff94@mail.gmail.com> In-Reply-To: <473c46620707122006l1bfcb981k6431c9228a25ff94@mail.gmail.com> X-Enigmail-Version: 0.95.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Either way is fine by me. I don't think there is a significant difference. Regards, Tim Spark Shen wrote: > 2007/7/12, Alexei Zakharov : >> >> Spark, >> >> I don't see many reasons to couple all persistence delegates into a >> single class. IMO "one class to one persistence delegate" model is >> obvious and easy to understand. AFAIU RI implements its persistence >> delegates in this way. BTW what do you mean by code duplication here? > > > For example, looking into the implementation for > java_lang_BytePersistenceDelegate & java_lang_DoublePersistenceDelegate. > They both have a instantiate method and an empty initialize method. > The instantiate method of BytePersistenceDelegate is like: > Byte value = (Byte) oldInstance; > return new Expression(oldInstance, Byte.class, "new",new Object[] { > value }); > > while the instantiate method of DoublePersistenceDelegate is like: > Double value = (Double) oldInstance; > return new Expression(oldInstance, Double.class, "new", new Object[] > { value }); //$NON-NLS-1$ > > IMHO, the logic are similar, and can be changed to: > return new Expression(oldInstance, oldInstance.getClass(), > "new", new Object[] { oldInstance }); > The situation exist for other primitive type persistence delegate. They are > the PDs I listed in my original post. > > The behavior of instantiate() method is unique to each PD and all that >> we can do is to create a single class with a big big switch that >> includes the code from all our PDs. Do we really want this? > > > I agree with you that a big switch is not a good method. I think we can > put > PrimitiveTypePersistenceDelegate into the persistenceDelegates in class > initializer instead of a big switch: > static PrimitiveTypePersistenceDelegate primitiveTypePD = new > PrimitiveTypePersistenceDelegate(); > static { > persistenceDelegates.put(int.class, primitiveTypePD); > persistenceDelegates.put(double.class, primitiveTypePD); > // etc. > } > There is another benefit here: we eliminate type name extraction logic for > primitive type. > >> IMHO it is >> not an Object-Oriented way. >> >> Sorry if I misunderstand your idea. Please explain in more details if so. >> >> Thanks, >> >> 2007/7/12, Spark Shen : >> > During developing PersistenceDelegate for java.lang.reflect.Field, I >> find >> > code duplication in many primitive type persistence delegate. >> > >> > There are 8 primitiveType persistenceDelegate: >> > java_lang_BooleanPersistenceDelegate >> > java_lang_BytePersistenceDelegate >> > java_lang_CharacterPersistenceDelegate >> > java_lang_DoublePersistenceDelegate >> > java_lang_FloatPersistenceDelegate >> > java_lang_IntegerPersistenceDelegate >> > java_lang_LongPersistenceDelegate >> > java_lang_ShortPersistenceDelegate >> > >> > Each of the 8 class has two method: instantiate & initialize, and the >> logic >> > of the 2 methods are similar. >> > IMO, we could use one PrimitiveTypePersistenceDelegate instead to >> reduce >> > code duplication. >> > -- >> > Spark Shen >> > China Software Development Lab, IBM >> > >> >> >> -- >> Alexei Zakharov, >> Intel ESSD >> > > >