title: Example with Visitor Pattern
body: <pre><code>public class Song {
      public string Genre { get; protected set; }
      public string Name { get; protected set; }
      public string Band { get; protected set; }
  
      public Song(string name, string band, string genre) {
          Name = name;
          Genre = genre;
          Band = band;
      }
  }
  
  public interface IMusicVisistor
  {
      void Visit(List&lt;Song&gt; items);
  }
  
  public class MusicLibrary {
      List&lt;Song&gt; _songs = new List&lt;Song&gt; { ...songs ... };
  
      public void Accept(IMusicVisitor visitor) {
          visitor.Visit(_songs);
      }
  }
  </code></pre>
  
  <p>and now here's one Visitor I made:</p>
  
  <pre><code>public class RockMusicVisitor : IMusicVisitor {
      public List&lt;Song&gt; Songs { get; protected set; }
  
      public void Visit(List&lt;Song&gt; items) {
          Songs = items.Where(x =&gt; x.Genre == "Rock").ToList();
      }
  }
  </code></pre>
  
  <p>Why is this any better than just putting a public property Songs and then letting any kind of class do with it anything that it wants to?</p>
  
  <p>This example comes from this <a href="https://stackoverflow.com/questions/2604169/could-someone-in-simple-terms-explain-to-me-the-visitor-patterns-purpose-with-ex/2604294#2604294">post</a>.</p>