Search code examples
c#.netdesign-patternsarchitecturepoker

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


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#.


Solution

  • 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.