Wednesday, December 17, 2008

What's in a name?

A rose by any other name....

Well not in software Romeo. Colin at Abstract.com posted an entry on obvious comments and how they probably indicate rubbish design/naming of methods and variables.

I am just stumbling into this kind of thing now. The client has asked for "Attachments" to be added to an entity in a system I am working on. When they say attachments they just want to upload documents and them to be linked to the entity. Sounds reasonable. So a developer has gone off and created an Attachment class.

I might be being picky here, but to me there is a subtle difference between Attachment, File and say Document or Image. Attachment describes a relationship, File describes an entity representing a file. You may sub class File with Document which might expose a Title, Subject Author properties. You may sub class File with Image and provide Width & Height Properties. But I doubt you would ever have a type of Attachment. If I wanted to add attachments to an entity I could call its void AddAttachment(File attachment) method with my uploaded document, image or simple file. To retrieve them I might use

IEnumerable<File> ListAttachments()
method or maybe just a simple
IEnumerable<File> Attachements
property.

Yeah its picky. Instead of just poking fun at someones design I may try to resurect an old design I had for this space (cheap and nasty DMS), and post it for public mockery.

No comments: