I am developing a small application in .NET and am thinking of using XML to save the object model.

My first thought was to separate the model and the generation of XML by using the Visitor pattern. The class would walk the object hierarchy and create the XML. But then I thought about the Extreme Programming method and the "you ain't gonna need it" (YAGNI) principle.

I don't envisage needing to create another Visitor to output the data in some other way (it's a simple app) I just want to use a human readable format to save the application's data.

Should I use the Visitor pattern or am I just over engineering the solution?


I don't really know enough about your application to be sure, but my feeling is that you are overengineering. You can't really code your application to cover every possible feature addition. Just keep it simple and be sure to avoid code duplication - if it turns out you need a visitor later, refactor it to a visitor.

A good book on the subject: http://www.amazon.com/Refactoring-Patterns-Joshua-Kerievsky/dp/0321213351

  • That's what I thought but it's hard to fight the instinct to create an application with clearly defined class resposibilities. I suppose I need to investigate how easy it is to stream objects to XML, it may not be too much work embedding the code in the objects to be saved.
    – Tony
    Apr 13 '11 at 13:36

.NET comes with an XmlSerializer built in. Here is an tutorial of how to use it. There is no need to write your own.

  • -1: Duplicate answer.
    – Jim G.
    Apr 13 '11 at 13:38
  • @Jim Your answer wasn't clear at all. I can see how someone wouldn't realize that you already posted about XmlSerializer.
    – Adam Lear
    Apr 13 '11 at 13:44
  • @JimG.: I down voted your answer because it did not address the question. This was before you added the link and before you crossed out database. My answer directly pointed out that there is built in functionality and it is not worth spending time worrying about the process. You don't need to down vote me just because I down voted you. Apr 13 '11 at 13:46
  • 1
    If my edit resolved your applicability or accuracy concerns, then you should remove your downvote.
    – Jim G.
    Apr 13 '11 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.