Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.meta.reflect.proxy
Interface Reference<T>

Type Parameters:
T - The type of the referenced object.
All Known Implementing Classes:
ReferenceHandler

public interface Reference<T>

A reference is used to handle the number of references to a given shared object: as long as only non-mutable methods are invoked on the referenced object, the object can be shared among several proxies. Once a given mutator method is invoked, the referenced object will be copied using a specified copy method.

Implementation notes:
This corresponds to a smart reference (or smart pointer) as described by Gamma et al. [Gamma95, p.209] and is thus an application of the Proxy pattern. It works via java.lang.reflect.Proxy objects. It corresponds to the Handle/Body C++ idiom described by Coplien.

Author:
Gunni Rode / rode.dk
See Also:
ReferenceInvocationHandler, ProxyFactory.getSharedObject(Object, String, Class[], String...)

Method Summary
 T addReference()
          Increases the reference count for the referenced object.
 Reference<T> copyIfMutator(Method method)
          Performs the actual copying of the referenced object if method is a mutator method and returns a new reference containing the copy with a reference count of one.
 boolean copyMethod(Method method)
          Returns true if the method supplied as method is the copy method used to copy the referenced object, false if not.
 T getReference()
          Returns the referenced object.
 

Method Detail

addReference

T addReference()
Increases the reference count for the referenced object.

Returns:
The referenced object; never null.

copyIfMutator

Reference<T> copyIfMutator(Method method)
                           throws Exception
Performs the actual copying of the referenced object if method is a mutator method and returns a new reference containing the copy with a reference count of one. The reference count for this reference will at the same time be decreased by one.

If method is not a mutator method, this reference is simply returned.

Parameters:
method - The method to test; cannot be null.
Returns:
The reference to use; never null.
Throws:
NullPointerException - If method is null.
Exception - If the copying fails.

copyMethod

boolean copyMethod(Method method)
Returns true if the method supplied as method is the copy method used to copy the referenced object, false if not.

Parameters:
method - The method to test; cannot be null.
Returns:
True if method is the method used to copy objects of the referenced object type, false if not.
Throws:
NullPointerException - If method is null.

getReference

T getReference()
Returns the referenced object.

Returns:
The referenced object; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.