commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] Delegates was Proposal for *NEXT* version
Date Fri, 04 Oct 2002 20:17:47 GMT
Split the thread as this bit got lost...

There are definite similarities between this Delegate description and the
code that is currently located in [pattern]. [pattern] contains four simple
callback interfaces Predicate, Transformer, Command and Factory. It also has
methods that support calling back to an arbitrary method using reflection.

Delegates take the approach of allowing any interface and calling back using
reflection.
The [pattern] case limits the interfaces to specific ones.
Otherwise they are similar.

There is a lot that can be done with delegates/BCEL/advanced beans. I would
really like to start getting this together, but I think that its a new
project [clazz] that builds on [lang].

Stephen

From: "Berin Loritsch" <bloritsch@apache.org>
> We threw together a way to generate Delegates.  A delegate is like a
> method pointer, but it is also able to be treated like an Object.  The
> benefit of this is that we can pass in the delegate to a method, and
> change the behavior of that method substantially.
>
> The perfect example where this pays off is with Intelligent Agent
> design.  The Intelligent Agent is the building block of artificial
> intelligence.  There are four or five basic algorithms for searching
> through a problem space to find the best solution.  These algorithms
> require you to pass in functions.  Delegates make all this possible,
> without forcing the original class to have the same name.  For example:
>
> interface NewComparator
> {
>      int compare( Object orig, Object other );
> }
>
> class ComparitorHeaven
> {
>      public int compareClassName( Object orig, Object other )
>      { /* implementation */ }
>
>      public int compareEquals( Object orig, Object other )
>      { /* implementation */ }
> }
>
> With the two declarations above, I can write a search algorithm
> like this:
>
> public Object findBestObject( String method )
> {
>      ComparatorHeaven ch = new ComparatorHeaven;
>
>      NewComparator checker =
>         (NewComparator) Delagate.newDelagate( ch, method );
>
>      Iterator it = m_myList.iterator();
>      Object prev = it.next();
>
>      while( it.hasNext() )
>      {
>          Object curr = it.next();
>          int preference = checker.compare( curr, prev );
>
>          prev = curr;
>          // perform actual decisions based on preference
>      }
> }
>
>
> We have some initial stuff checked in to Excalibur Util.
> When we are done shaping it up, we would like to give it
> to Commons Lang.  I realize you are getting ready to make
> a release, which is why I don't want to push it for this
> release.  What are y'alls thoughts?



--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message