I’m creating two separate classes for accessing a custom file. Let’s call my classes MyReader and MyWriter.
I’m following the same pattern that .NET classes such as StreamReader and StreamWriter follow, where there is a separate class for reading and writing. In addition to following an established pattern, this also solved some other problems for me.
However, I really need a few common settings for both the reader and writer classes. For example, I have a delimiter character that the user should be able to change. I also have some fixed data that contains common information used for parsing.
Could someone suggest a good pattern, especially one that follows common .NET framework practices, for creating common settings for multiple classes like this? My classes already inherit from a .NET class. Seems like multiple inheritance might have been one way but doesn’t seem supported in C#.
(I’m using Visual Studio 2012.)
This seems to be one of those rare instances where a Singleton might make good sense:
Hope this helps.