|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
I
- Type interface that this IDelegator
builds.public interface IDelegator<I>
Delegates Design Pattern: Allows multiple objects implementing
methods with different names but compatible signatures to be used
interchangeably. It will also work with or without a target interface
to implement i.e. using IDelegate
.
The IDelegator
interface simplifies and generalizes the
steps in creating an Adapter. Delegates are simple to use, and
a single delegate instance may be reused multiple times.
Responsibility: Definition of "Delegator".
Notes: Base source code implemented by Steve Lewis and Wilhelm
Fitzpatrick and adapted to fit PerfectJPattern componentization
criteria and code conventions.
Example usage:
//
// Example class that defines two methods that match in signature
//
class Example
{
//--------------------------------------------------------------------
public static void
staticMethod(String aValue)
{
System.out.println(aValue);
}
//--------------------------------------------------------------------
public void
memberMethod(String aValue)
{
System.out.println(aValue);
}
}
//
// Defines a common interface with method printValue
//
interface IPrinter
{
//--------------------------------------------------------------------
public void
printValue(String aValue);
}
//
// Create instance of example class
//
Example myInstance = new Example();
//
// Example using DynamicDelegator without well defined target interface
//
IDelegator<IDelegate> myDynamicDelegator = new DynamicDelegator(
Void.TYPE, String.class);
//
// Build appropriate IDelegate references
//
IDelegate myDelegate1 = myDynamicDelegator.build(Example.class,
"staticMethod");
IDelegate myDelegate2 = myDynamicDelegator.build(myInstance,
"memberMethod");
//
// Use the Delegate references to invoke the target methods.
//
myDelegate1.invoke("Value1");
myDelegate2.invoke("Value2");
//
// Example using well defined target interface
//
IDelegator<IPrinter> myPrinterDelegator = new Delegator(
IPrinter.class);
//
// Build appropriate IPrinter references
//
IPrinter myPrinter1 = myPrinterDelegator.build(Example.class,
"staticMethod");
IPrinter myPrinter2 = myPrinterDelegator.build(myInstance,
"memberMethod");
//
// Use the IPrinter interface reference.
//
myPrinter1.printValue("Value1");
myPrinter2.printValue("Value2");
Method Summary | |
---|---|
I |
build(Class aTarget,
String aMethodName)
Returns Dynamic Proxy that implements the target generic parameter interface. |
I |
build(Object aTarget,
String aMethodName)
Returns Dynamic Proxy that implements the target generic parameter interface. |
Method Detail |
---|
I build(Class aTarget, String aMethodName) throws IllegalArgumentException, UnsupportedOperationException
aTarget
- non-null class with a bindable static method.aMethodName
- name of the static method.
UnsupportedOperationException
- No suitable method found.
IllegalArgumentException
- 'aTarget' must not be null.
IllegalArgumentException
- 'aMethodName' must not be null.I build(Object aTarget, String aMethodName) throws IllegalArgumentException, UnsupportedOperationException
aTarget
- non-null target with a bindable method.aMethodName
- name of the method.
UnsupportedOperationException
- No suitable method found.
IllegalArgumentException
- 'aTarget' must not be null.
IllegalArgumentException
- 'aMethodName' must not be null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |