<soap-box>
I won't be surprised Java's introduction of Dynamic Proxy is an answer to 
Hejlsberg's criticism.

I remember when C# was first introduced, there was this interview with 
Hejlsberg who criticized Java's adaptor pattern and later Gosling responded 
by calling Hejlsberg the "pointer man".

I tried to find the webpages but couldn't. The only thing I found on 
java.sun.com is a white paper on "About Microsoft's Delegates [vs. Java's 
inner classes]"

   http://java.sun.com/docs/white/delegates.html

</soap-box>


Initially, when Berin said he wanted to "generate" delegates, I got the 
wrongly impression Berin wanted to do code generation. (i.e. Doing what 
AspectJ is doing now: introduce some new syntax at the language level and 
do a pre-processing to speak out plain java code.)

Now I understand we're actually talking about a thin wrapper of dynamic 
proxy. I second the idea. Even delegates and inner classes are semantically 
equivalent at the byte-code level, the "syntax sugaring" offered by C#'s 
delegates saves a lot of repetitive and verbose code.

This leads me to think of a related idea. I used to code in Delphi. In 
Delphi, creating properties is declarative, not like the tedious and 
verbose JavaBean setter/getter idiom. e.g.

   type
     TMyObject = class(TObject)
     private
       FName : String;
       FAge : integer;
       procedure SetNameWithValidation(Name: String);
     property
       Name : String read FName write SetNameWithValidation;
       Age : integer read FAge write FAge;

Notice the flexibility of allowing binding either raw attributes or methods.

I haven't thought it through how this can be achieved in Java (and how to 
cleanly get around the security manager). But if we can doing the 
following, it'll be really cool:

   public class MyClass {
     private int fAge;
     private String fName;

     static {
       BeanInfoUtils.expose(MyClass.class, "name", "fName", 
"setNameWithValidation");
       BeanInfoUtils.expose(MyClass.class, "age", "fAge", "fAge");
     }

     private void setNameWithValidation(String name) {..}
   }

Then, the properties can be accessed by PropertyUtils:

   PropertyUtils.setProperty(myObj, "name", "John Yu");
   PropertyUtils.setProperty(myObj, "age", new Integer(42));

Comment?
--
John


At 03:02 am 04-10-2002, you wrote:
>Steve Downey wrote:
>> From 
>> http://msdn.microsoft.com/library/en-us/dndevqa/html/msdn_andersh.asp, 
>> an interview with Anders Hejlsberg, the original architect of Borland's 
>> Delphi, regarding some of the work he had done for the "Windows 
>> Foundation Classes", part of Microsoft's  J++ product, after he jumped 
>> ship from Borland.
>>His work was later adopted into C#.
>
><snip type="article"/>
>
>That was a very interesting read.  I'm sold on Delegates as a way of
>doing things.  We basically did the only thing we could do without
>extending the language--although it would be nice to have a JSR for
>this puppy.
>
>I tell you, it will make it alot easier for certain GUI apps....
>
>myButton.addActionEventListener(
>     Delegate.newDelegate(
>         this, "handleMyButton", ActionEventListener.class ) );
>
>And the logic goes in a method:
>
>public void handleMyButton( ActionEvent event )
>{
>    // perform logic
>}
>
>And that's without modifying Swing!

-- 
John Yu                       Scioworks Technologies
e: [EMAIL PROTECTED]         w: +(65) 873 5989
w: http://www.scioworks.com  m: +(65) 9782 9610 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to