Re: Class Design Question



Cool Guy <coolguy@xxxxxxx> wrote in message news:<qu1othydy4or.dlg@xxxxxxxxxxxxxxxx>...
> I have a class which holds key-value pairs where the keys are common
> Windows file extensions and the values are associated file content
> descriptions (for each extension).
>
> This class has a method which gets a value given a key.
>
> e.g.:
>
> class FileDescriptionTable {
> public void Get(string fileExtension) {
> return GetDescription(fileExtension);
> }
> }
>
> I was considering changing it so that, instead of taking a key (a file
> extension), it takes a full file name, and determines the extension itself
> (by making a routine call):
>
> class FileDescriptionTable {
> public void Get(string fileName) {
> return GetDescription(FileUtility.GetExtension(fileName));
> }
> }
>
> Is this a good idea, or would it give FileDescriptionTable too much
> responsibility? I can't quite decide.


Hej!

By naming your class, "FileDescriptionTable," you are nominally
defining it as connected with files, so I think passing it the full
file name and letting it get the extension seems reasonable. This
class is defined by its handling of files, so adding some more
file-handling functionality looks fine.

If, however, your application has another entity whose name
necessarily defines an associated description, for example a GUI
button and a tooltip, or a database field header and a description of
the entries that are allowed under that header, then you could
probably re-use some of the above code, in which case you'd change the
class name from, "FileDescriptionTable," to something like,
"KeyDescriptionTable." If you do this, then it may no longer be
appropriate for such a generic class to access something as specific
as a FileUtility, and so passing just the file extension might be a
better solution.

(Note that if you do take the latter approach, you can have the best
of both worlds: instead of get(String fileName), you could pass in an
abstract class get(Key key), and Key would have method getName() to
return a string; thus, if a subclass FileNameKey could be
parameterised by a file name and deduce the extention via getName(),
and FileExtentionKey could be parameterised by just the file extention
and return this unaltered via getName().)

..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
.



Relevant Pages

  • Re: Add File Extention
    ... I agree with John Inzer. ... There is no need to rename and add the extension. ... The extension is there, ... > The files are fine but I have to go in and add a file extention to them. ...
    (microsoft.public.windowsxp.photos)
  • Re: How do I search for n find files with no extentions?
    ... = everything with no extension ... Cloudchaser the Red Wolf furry wrote: ... I just found that there may be several files on my external HD that got saved with no file extention and while I know that I can, for example, find all jpg's by entering ".jpg" in "allor part of the filename," I have no idea how to get it to search for all files that have no extention. ...
    (microsoft.public.windowsxp.general)
  • how icon associated with extension?
    ... how get icon structure associated with extension? ... if my file extention is then how and where i get icon of document ...
    (microsoft.public.dotnet.languages.vc)
  • how icon associated with extension?
    ... how get icon structure associated with extension? ... if my file extention is then how and where i get icon of document ...
    (microsoft.public.vc.mfc)