Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created June 27, 2011 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Riduidel/1048734 to your computer and use it in GitHub Desktop.
Save Riduidel/1048734 to your computer and use it in GitHub Desktop.
An example adaptable interface
/**
* Shamelessely borrowed from Eclipse concepts, as this article explains the
* interest of this approach :
* http://www.manageability.org/blog/stuff/adaptor-oriented-programming/view
* There is also an article in Eclipse site :
* http://www.eclipse.org/articles/article.php?file=Article-Adapters/index.html
* but it is a little too much Eclipse centric for me
*/
public interface Adaptable {
/**
* Check if this adaptable can be adapted to the given class.
* @param classToAdapt the class we want to know if we can adapt to
* @return true if we can adapt to that class, false elsewhere
*/
boolean canAdapt(Class<?> classToAdapt);
/**
* The component adaptation process performed by getAdapter() proceeds in
* four steps:
* <ol>
* <li>If adapter is an interface that this implements then return this
* unchanged. (Note: This trivial case is usually not done by most
* implementors of this method ).</li>
* <li>If the method can find a matching adapter, return an instance that
* implements the adapter.<//li>
* </ol>
* @param classToAdapt the class to adapt. Basically, an instance of that class corresponding to this object will be returned
* @return an exception if {@link #canAdapt(Class)} return false for that class, otherwise an instance of that class adapting this object
*/
<AdaptedType> AdaptedType getAdapter(Class<AdaptedType> classToAdapt) throws UnableToAdapt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment