|
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 this stringable object.@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.
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 |
|---|
StringablePolicy<? super T> getStringablePolicy(StringablePolicy<? super T> policy)
policy is not null: policy is returned.
policy is null: a default, non-null policy is returned.
policy - The supplied policy; can be null.
toString(StringablePolicy)CharSequence toString(StringablePolicy<? super T> policy)
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:
policy decide the entire format,
as in the Foo example above; or
policy to format part of the overall
representation, for example letting this method append
certain text regardless of the policy used.
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.
policy - The policy to dictate the formatting; can be null, in
which case the result of toString method
is returned.
StringablePolicy.Type
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||