Pages

Wednesday 1 August 2007

A reflection of generic thoughts attributed to software design

Techniques such as Reflection, Attribute-based programming and Generics (to name a few) provides the developer with a high degree of flexibility when designing today's software components and classes. Flexibility in design is a key notion that should be nurtured well, and with proper paradigms and patterns in place, should allow for adaptable constructs to be developed.

I put myself to task with a simple problem: Create a mechanism that allows importing CSV files. Each type of CSV file would represent an object in the real world. There would be a CSV file for Employees, with their details, another one for Departments, with department details and so on.
The number of CSV files, and their internal record structure can vary drastically.

You must make your class design flexible enough that with minimal effort, you are able to model different types of files and objects; you must ensure flexibility and minimum amount of work in modelling new objects and minimum re-work when modifying existing classes to suit new record structures.

I thought about this for a while, and came up with a solution involving reflection, attributes, generics and even a factory design pattern. I might have gone way over my head, but feel free to read my article at CodeProject, get a head about what's going on and tell me what you think.

After all, programming is sometimes just damn fun. :)

1 comment:

  1. Hi there, I came here via your CodeProject article, and I just have to say that it must be true that "great minds think alike." Your approach is amazingly similar to the approach used by the FileHelpers project (of which I am a developer), an LGPL-licensed library written in C# and which uses the same attribute-centred approach to parsing not only CSV files, but any delimited or even fixed-width file format.

    Please come check out our library and see what you think. Naturally, you're doing some stuff differently in your article than we have been, but the overall approach is very similar. Right now there's just the 2 of us maintaining the project (myself and the original author Marcos), and we could definitely use a "fresh perspective" in our project, and I think it would be great if you could contribute suggestions or even some code improvements to our project.

    Cheers,
    Matt

    ReplyDelete