Re: API design
Stefan Ram wrote:
I assume that one wants to design an API with the option to
open a FileOutputStream for /append mode/. There are several
possibilities, and one can compare their readability,
extendability (fitness for later API extensions), usability
and other software quality factors. (feel free to comment):
==
new FileOutputStream( "path", "a" );
Meh.
==
new FileOutputStream( "path", "append" );
Eh, verbose is good, string is bad.
==
new FileOutputStream( "path", true );
Ew, no.
==
new FileOutputStream( "path", FileOutputStream.APPEND_MODE );
Sure, if that is an enum value.
==
new FileOutputStream( "path", FileAccessMode.APPEND_MODE );
Sure, if that is an enum value.
==
new FileOutputStream( path, new AppendMode() );
/* here, ?AppendMode? might be a subtype of another type ?FileAccessMode? */
No, because a user would then be able to create a new FileAccessMode
class that doesn't make sense to FileOutputStream.
==
new FileOutputStream( path, new FileAccessMode( "append" ));
Only slightly better than (path, "append").
==
new AppendFileOutputStream( path );
No.
/* here, ?AppendFileOutputStream? might be a subtype of ?FileOutputStream? */
==
Possibly, I have missed others possibilities to design this.
Another possibility: FileOutputStream.openForAppend(path);
Although, I still would prefer FileAccessMode.APPEND_MODE over all the
others for this particular case.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>