dk.rode.thesis.prototype
Interface Copyable<T>
- Type Parameters:
T
- The type of copyable object.
- All Known Subinterfaces:
- AspectObservableSequence<O,A,E>, Command<E>, ComparableExpressionBuilder<E>, CompositeSequence<E>, Expression<E>, ExpressionBuilder<E>, InitialisableExpression<E>, MemorizableSequence<E>, NonTerminalExpression<E>, ObservableSequence<O,A,E>, ReversibleSequence<E>, Sequence<E>, SequenceValueGenerator<E>, StateableSequence<E>, StepSequence, StrictCopyable<T>, TerminalExpression<E>, TypedExpression<E>, TypeVisitableSequence<E>, ValueVisitableSequence<E>
- All Known Implementing Classes:
- AbstractCompositeSequence, AbstractExpression, AbstractExpressionBuilder, AbstractSequence, AbstractStateableSequence, AbstractVisitableSequence, AckermannSequence, AndExpression, AnnotatedObserversSequence, AnnotatedObserversSequenceDecorator, AppenderDecorator, ArraySequence, AssignmentExpression, BinaryExpression, BreakExpression, CharSequenceCompositeSequence, CompareExpression, CompositeCommand, ConditionalExpression, ConstantExpression, CountdownSequence, CountingComparableExpressionBuilder, CountingExpressionBuilder, CurrentExpression, DanishAlphabetSequence, DateSequence, DateValuedVisitableSequence, DigitSequence, DuplexDecorator, EnglishAlphabetSequence, EqualExpression, EvenSequence, EvilCommand, FibonacciSequence, FileSequence, FlowExpression, HexDigitSequence, ImmutableSequence, IntegerValuedVisitableSequence, IterableSequence, LogCommand, LongSequence, MemorizableEnglishAlphabetSequence, MemorizableSequenceAbstraction, MutatedSimpsonsFamilySequence, NegativeSequence, NextCommand, NextExpression, NonResettableSequence, NorwegianAlphabetSequence, NotExpression, NullCommand, OddSequence, OrExpression, PrimeSequence, ProcessableSequence, RandomSequence, RangeSequence, ReflectiveVisitableSequence, ResetCommand, ResetExpression, ReverseCommand, ReverseExpression, ReversiblePrimeSequence, Sentence, SequenceAbstraction, SequenceAdapter, SequenceCommand, SequenceDecorator, SequenceExpression, SequenceObserversSequence, SequenceObserversSequenceDecorator, SequenceTemplate, SequenceValueArrayList, SequenceValueCollection, SequenceValueHashSet, SequenceValueLinkedHashSet, SequenceValueRange, SequenceValueSet, SequenceValueTreeSet, SetExpression, SimpsonsAndBouvierFamilySequence, SimpsonsFamilySequence, SmileySequence, StandardComparableExpressionBuilder, StandardExpressionBuilder, StepSequenceImpl, StringValuedVisitableSequence, SymbolSequence, SynchronisedSequence, SynchronisedSequenceAbstraction, TypedComparableExpressionBuilder, TypedExpressionBuilder, TypedExpressionDecorator, TypedFlowExpression, UnboundedRandomSequence, UppercaseDecorator, VariableExpression, VisitableCompositeSequence, VisitableLongSequence, VisitableRandomSequence, VisitableReversiblePrimeSequence, Word, ZipSequence
@Participant(value="Prototype")
public interface Copyable<T>
A copyable object can return a deep copy of it self
any type implementing this interface can act as a prototype.
Though not required, it is prudent to supply a copy constructor
for any type implementing the Copyable
interface.
Implementation notes:
The Copyable
interface is generic, accepting the type parameter
T
that determines the type of the returned copy. The type parameter
is used for type safety reasons (as opposed to simply returning Object
).
Though it cannot be enforced, T
is expected to be the implementing
type itself. If a bound like <T extends Copyable<T>>
had been
used instead of just T
, the PrototypeFactory
would not have
been able to generate dynamic proxies to represent prototypical
objects that dynamically implements Copyable
for any object
type: the original type(s) could not be guaranteed to satisfy the
extends Copyable
bound. If such a bound is to be enforced,
the StrictCopyable
type can be used.
Sub-interfaces can use covariant return types to refine the type
of the returned copy even further. This is sometimes even required. An
example of this is the Expression
and TypedExpression
interfaces used in the Interpreter
pattern. TypedExpression
extends Expression
to augment
normal expressions with runtime type information. If it had not overridden
the copy()
method from Expression
that returns an
Expression
, copying a TypedExpression
would return
an Expression
, not a TypedExpression
. Hence, the
compile-time behaviour of TypedExpression
is not accessible
without explicit casting if copied. By declaring the copy()
method to return a TypedExpression
no casting is required.
- Author:
- Gunni Rode / rode.dk
- See Also:
PrototypeFactory
Method Summary |
T |
copy()
Returns a deep copy of this object. |
copy
T copy()
- Returns a deep copy of this object.
- Returns:
- The copy; never null.
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.