Search code examples
javaclass-design

Class design - where to put certain methods?


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?


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!