|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
T
- The type of the referenced object.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.
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 |
---|
T addReference()
referenced
object.
Reference<T> copyIfMutator(Method method) throws Exception
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.
method
- The method to test; cannot be null.
NullPointerException
- If method
is null.
Exception
- If the copying fails.boolean copyMethod(Method method)
method
is the copy method used to copy the referenced
object, false if not.
method
- The method to test; cannot be null.
method
is the method used
to copy objects of the referenced object type,
false if not.
NullPointerException
- If method
is null.T getReference()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |