Why does toString() exist? It seems useless.
Frank Benoit
keinfarbton at googlemail.com
Mon Aug 18 06:33:58 PDT 2008
Don schrieb:
> OTOH if it is intended for general I/O, I think it's a horribly broken
> design.
What do you think about doing one of
1.)
change signature in object.Object to
char[] toString( char[] fmt = null)
to give the object the possibility to use the format information.
Well, would break all code :/
2.)
Create a standard interface for doing that
interface Formatable {
char[] toString( char[] fmt );
}
The object can implement this interface, the user can try to cast to
this interface.
if( auto formatable = cast(Formatable)obj ){
print( formatable.toString(fmt));
}
else if( obj !is null ){
print( obj.toString());
}
else{
print( "null" );
}
More information about the Digitalmars-d-learn
mailing list