This is part moot of inconsequential posts on my professional development odyssey in which I try to develop an online music library application using whatever techniques and technology strike my fancy at the time. Code can be found at: svn:// if memory serves.

In our last episode, I popped up an initial test to see if we could retrieve all songs by an artist. I've since added a test, ShouldBeAbleToRetrieveSongsWithPartialTitle, that tests to see if we can retrieve songs by title (or partial title). It's not altogether interesting so I'll skip it here.

The next test was ShouldBeAbleToRetrieveSongsByGenre which garners slightly more air time because if the notion of a Genre. Here is the test in its current incarnation:

  [ Test ]
  public void ShouldBeAbleToRetrieveSongsByGenre( )
      Genre genre = new Genre( "Really &*%$ old" );
      int numberOfSongs = songRepository.GetSongsByGenre( genre ).Count;
      using ( mockery.Record( ) )
          ISong fakeSong = mockery.DynamicMock<ISong>( );
          SetupResult.For( fakeSong.Genre ).Return( genre );
          songRepository.AddSong( fakeSong );
      Assert.AreEqual( numberOfSongs + 1, 
new Genre(
"Really &*%$ old" ) ).Count ); }

And here is the GetSongsByGenre method:

    public IList<ISong> GetSongsByGenre( Genre genre )
        List<ISong> songsWithGenre = new List<ISong>( );
        foreach ( ISong song in songList )
            if ( song.Genre.Equals( genre ) )
                songsWithGenre.Add( song );

        return songsWithGenre;

(NOTE: No this isn't my final implementation. But it's enough to pass the tests for now.)

I've decided to make the Genre a Value Object which you might be able to determine from the comparison in GetSongsByGenre. The inital reason for this is that a Genre seems like it should be an object and I'd like to be able to compare two songs' genres.

But as I write this, I realize I probably should apply the same thinking to an artist. If a genre is to be its own object, why not use an Artist object rather than a string? For the purpose of our application, both are to be used identically (i.e. as search criteria and metadata on a song).

So I should create an Artist object, yesno? Now it's starting to sound more complicated than it probably needs it to be. Do I care about genres or artists other than as a property on the song? Is there any other data about them that is interesting to me?

At this point, I'd say the answer is no. Certainly for genres. But also for artists for the moment. Maybe we'll get to the point where we want to store the names, birthdates, country, aliases, and a little bio on each one but for now, I believe it's time to demote Genres back to a string.

Kyle the Devalued