I became familiar with this extension of the Adapter pattern when I started
writing plugins for Eclipse. Eclipse has a similar class,
org.eclipse.runtime.core.AdapterManager, that is used a lot.
The AdapterManager is absolutely addicting. I will never again go without
an 'AdapterManager'. And I hardly ever write code like this anymore...
MyInterface lInterface= (MyInterface)someClass;
...I always write...
MyInterface lInterface=
(MyInterface)AdapterManager.getAdapter(MyInterface.class, someClass);
The AdapterManager is especially useful when some plugin wants to add an
interface to objects that were created by another third party plugin.
However, I haven't yet created one for myself for use outside of Eclipse.
I already use commons lang and would very much like to see the
AdaptorRegistry added.
thanks,
ted stockwell
jlense.sf.net
> -----Original Message-----
> From: Howard M. Lewis Ship [mailto:[EMAIL PROTECTED]]
>
> Tapestry already uses a lot of Jakarta commons stuff (-lang,
> -logging).
> There are some utility classes in Tapestry that I would love
> to move into
> commons-lang.
>
> One very useful candidate is AdaptorRegistry. It's my
> attempt to bring
> logic, similar to Objective-C categories, to Java. You can
> also think of it
> as lightweight aspects.
>
> http://jakarta.apache.org/proposals/tapestry/doc/clover/net/sf
> /tapestry/util
> /AdaptorRegistry.html
>
> This is my take on a general implementation of the GoF
> Adaptor pattern. You
> use an AdaptorRegistry to adapt objects with fixed interfaces to new
> situations. You create adaptor objects and register them.
> Adaptors are
> registerred in terms of a class or interface.
>
> You then supply a subject object. A search occurs, where the
> AdaptorRegistry looks for a matching adaptor. It first works up the
> inheritance hierarchy, looking for a matching superclass. It
> then works
> through all the interfaces directly, or indirectly, implemented by the
> object until it finds a match.
>
> In practice, you define an adaptor interface that takes, as
> an argument, an
> object. You them provide different implementations, where
> you cast the
> object to specific types and perform operations on or using them.
>
> This tends to replace code that is a series of "if (foo
> instanceof Bar) ..."
> with a lookup of an adaptor. Of course, you can register
> adaptors in any
> order, at any time.
>
> AdaptorRegistry has an amazing 100% code coverage test suite.
>
> It is ready for "harvest" from Tapestry. It would be minimal work to
> decouple it from Tapestry (it uses some static methods to access a
> framework-common ResourceBundle).
>
> I may find some spare cycles to provide a patch to
> commons-lang, if you are
> interested in the code.
>
>
>
**********************************************************************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>