Design Pattern: Parsing similar, but differing schemas in text files


Question

thanks in advance for your help. I am wondering if there is a (design) pattern that can be applied to this problem.

I am looking to parse, process, and extract out values from text files with similar, but differing formats.

More specifically, I am building a processing engine that accepts Online Poker Hand History files from a multitude of different websites and parses out specific data fields (Hand #, DateTime, Players). I will need the logic to parse the files to be slightly different for each format, but the processing of the extracted values will be the same.

My first thought would be to create just 1 class that accepts a "schema" for each file type and parses/processes accordingly. I am sure there is a better solution to this.

Thanks!

Bonus Point: Any specific implementation hints in C#.

1
8
12/2/2008 3:46:24 PM

Accepted Answer

This sounds like a candidate for the Strategy pattern. An example in C# can be found here and another one here. A brief description is available on Wikipedia.

More complete descriptions is available in book by Fowler and Kerievsky.

It is also available from the GoF book.

6
12/2/2008 4:01:08 PM

The "Provider" pattern is the one you're looking for... it is what is used in ADO.Net. Each database vendor has a separate data "Provider" that "knows" how to read the data from it's specific DB vendors product, but delivers it in a standard format (interface) to downstream systems... You will write a small "Provider" component (a single class will suffice) that "knows" the format for each of your different website poker history data providers, and exposes that data in exactly the same way to the upstream system that reads it...


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon