Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Why can't you just serialize the object to the database? – Jim G. Apr 13 '11 at 13:32
up vote 2 down vote accepted

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:

share|improve this answer
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.

share|improve this answer
-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. – unholysampler Apr 13 '11 at 13:46
+1: Thanks for the link to the tutorial. – Tony Apr 13 '11 at 13:55
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 posting your answer, you agree to the privacy policy and terms of service.

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