Question

For an assignment I have to create a song/playlist organising program.

The song/playlist have the obvious members + constructors & getters/setters, and the driver reads from 2 files & creates an array of songs, and an array of playlists. (I can't use arraylist).

My question is in regards to some additional functionality i have to provide, such as sorting the songs by title, searching the songs, etc. Where should I be putting these methods?

I'm thinking it should either be a static method of the song class, or perhaps in a separate SongUtils class (and a PlaylistUtils class). Or should i just do it in the driver?

What do you guys think?

Was it helpful?

Solution

I would suggest you to create a dedicated class such as Songs or SongCollection which holds a collection of songs and can manage them in a way of exposing a proper API for the user.

This class can expose methods such as sortListByComparator and this method would get a different Comparator object as a parameter and will sort the collection according to it.

I hope that will help as a start...

Good luck buddy!

OTHER TIPS

What I can think of:

  • Have Song class to create your song objects.
  • Have Playlist class that contain your array of songs.
  • Your Main class should have your song list and playlist list (that means array of songs and array of playlists)
  • If you want functionality to sort/search IN A CERTAIN PLAYLIST, then write the method in the Playlist class.
  • If you want functionality to sort/search FROM ALL YOUR SONGS/PLAYLIST, then write the method in the Main class.

This is just a suggestion :) Hope it helps :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top