假设我有一些XML、JSON或YAML格式的文件中的数据。所有文档都具有相同的逻辑结构。在简单情况下:所有文件都有根元素属性版本。
我打算创建一个类,它可以从/文件中读取和写入数据,这样的格式:
enum FileFormat {JSON, XML, YAML};
class File {
FileFormat FileFormat { get; } // We cannot change file format
int Version { get; set; } // We can read/change root attribute Version
Load(string fileName, FileFormat fileFormat); // We can load from JSON/XML/YAML formats
Save (string fileName); // We can save changed in the same format as we read
}在Load/Save中应该使用哪种设计模式来选择正确的序列化程序/反序列化器?
发布于 2014-10-20 14:44:14
这是建造者模式的教科书场景。
https://stackoverflow.com/questions/26453161
复制相似问题