public interface FlyweightPrototype<T extends FlyweightPrototype<T>>
Flyweight copies are useful to implement multithreading on read-only (but maybe stateful) classes. An instance of a class implementing this interface is not necessarily thread safe, but it can be (thread-) safely copied many times (i.e., it can be used as a prototype). All copies will share as much as possible of the class read-only state (so they are flyweight).
In the case an implementation is stateless, it can of course return always the same singleton
instance as a copy. At the other extreme, a stateful class may decide to synchronise its
methods and return itself as a copy instead. Note that in general the object returned
copy() must replicate the current state of the object, not
the object state at creation time. This might require some calls to methods that
modify the class internal state: in particular, one should always check whether such
methods are pointed out in the documentation of superclasses.
Implementing subclasses are invited to use covariant return-type overriding to
copy() return the right type.
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.