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

dk.rode.thesis.strategy
Interface Stringable<T extends Stringable<? super T>>

Type Parameters:
T - The type of this stringable object.
All Known Subinterfaces:
AspectObservableSequence<O,A,E>, Character, CompositeSequence<E>, MemorizableSequence<E>, ObservableSequence<O,A,E>, ReversibleSequence<E>, Sequence<E>, SequenceValueGenerator<E>, StateableSequence<E>, StepSequence, TypeVisitableSequence<E>, ValueVisitableSequence<E>
All Known Implementing Classes:
AbstractCharacter, AbstractCompositeSequence, AbstractSequence, AbstractStateableSequence, AbstractVisitableSequence, AckermannSequence, AnnotatedObserversSequence, AnnotatedObserversSequenceDecorator, AppenderDecorator, ArraySequence, CharSequenceCompositeSequence, CountdownSequence, DanishAlphabetSequence, DateSequence, DateValuedVisitableSequence, DigitSequence, DuplexDecorator, EnglishAlphabetSequence, EvenSequence, FibonacciSequence, FileSequence, GuardedSequenceMemento, HexDigitSequence, ImmutableSequence, IntegerValuedVisitableSequence, IterableSequence, Letter, LongSequence, MemorizableEnglishAlphabetSequence, MemorizableSequenceAbstraction, MutatedSimpsonsFamilySequence, NegativeSequence, NonResettableSequence, NorwegianAlphabetSequence, OddSequence, PrimeSequence, ProcessableSequence, RandomSequence, RangeSequence, ReflectiveVisitableSequence, ReversiblePrimeSequence, Sentence, SequenceAbstraction, SequenceAdapter, SequenceDecorator, SequenceIterator, SequenceMemento, SequenceObserversSequence, SequenceObserversSequenceDecorator, SequenceTemplate, SequenceValueArrayList, SequenceValueCollection, SequenceValueHashSet, SequenceValueLinkedHashSet, SequenceValueRange, SequenceValueSet, SequenceValueTreeSet, SimpsonsAndBouvierFamilySequence, SimpsonsFamilySequence, SmileySequence, StepSequenceImpl, StringValuedVisitableSequence, Symbol, SymbolSequence, SynchronisedSequence, SynchronisedSequenceAbstraction, UnboundedRandomSequence, UppercaseDecorator, VisitableCompositeSequence, VisitableLongSequence, VisitableRandomSequence, VisitableReversiblePrimeSequence, Whitespace, Word, ZipSequence

@Participant(value="Context")
public interface Stringable<T extends Stringable<? super T>>

A stringable object can be formatted into different textual char sequence representations using a given policy to determine the format.

Author:
Gunni Rode / rode.dk
See Also:
StringablePolicy

Method Summary
 StringablePolicy<? super T> getStringablePolicy(StringablePolicy<? super T> policy)
          Always return a non-null policy: policy is not null: policy is returned.
 CharSequence toString(StringablePolicy<? super T> policy)
          Returns a char sequence representation of this stringable object using the format determined by policy or the default policy in case policy is null.
 

Method Detail

getStringablePolicy

StringablePolicy<? super T> getStringablePolicy(StringablePolicy<? super T> policy)
Always return a non-null policy:

  1. policy is not null: policy is returned.

  2. policy is null: a default, non-null policy is returned.

Parameters:
policy - The supplied policy; can be null.
Returns:
The policy to use; never null.
See Also:
toString(StringablePolicy)

toString

CharSequence toString(StringablePolicy<? super T> policy)
Returns a char sequence representation of this stringable object using the format determined by policy or the default policy in case policy is null.

In Foo, a typical implementation of this method could be:

    public CharSequence toString(StringablePolicy<? super Foo> policy) {
      return this.getStringablePolicy(policy).toString(this);
    }
 
There are two approaches to formatting this stringable object into a char sequence representation:

  1. Let policy decide the entire format, as in the Foo example above; or

  2. Use policy to format part of the overall representation, for example letting this method append certain text regardless of the policy used.

Bullet 1) is not always applicable because a given policy implementation may not have access to all required information in its StringablePolicy.toString(Object) method, for example in case multiple stringable objects should be formatted into an overall representation.

In case an implementation uses the approach from bullet 2), care must be take to respect the policy hints so the overall format remains meaningful.

Parameters:
policy - The policy to dictate the formatting; can be null, in which case the result of toString method is returned.
Returns:
The char sequence representation; never null.
See Also:
StringablePolicy.Type

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.