0
Song{
    int Songid;
    String name;
    Artist Artist;
    Album album;
    void play();
}

Album{
    int albumid;
    String name;
    Artist albumArtist;
    ArrayList<Song> songs;
    ArrayList<Song> getSongs();
}

Artist{
    int arId;
    String name;
    ArrayList<Album> albums;
    ArrayList<Song> songs;
    ArrayList<Album> getAlbums();
    ArrayList<Song> getSongs();
}

I am confident about the int and String members of every class. But does the Object type members show redundancy ? I want every method to work as fast as possible .

I will require to show name of album of around 10,000 songs. and on certain events will require to get songs of a particular album.

So I have though that when Song.album is assigned, album.songs.add(song) will also be done automatically.

Radiodef
  • 37,180
  • 14
  • 90
  • 125
user3733814
  • 105
  • 1
  • 10
  • 1
    There's often no value in maintaining cyclic dependencies, nor there is to store the object reference rather than the identity. – plalx Apr 19 '15 at 02:59
  • What if a Song belongs to more than one Album. (ex. orig recording or greatest hits)? What's the difference between Album.songs or getSongs? – seand Apr 22 '15 at 03:37

2 Answers2

0

Something like this

Artists
    artist_id
    name

Albums
    album_id
    artist_id
    album_name

songs
    song_id
    album_id
    artist_id
    song_name

By choosing that layout, you can run various queries, no redundancy save for in songs where artist id could be omitted. however if you have a song you could show the artist without the extra overhead of joining the album into query.

CodingInTheUK
  • 930
  • 7
  • 16
  • I will require to show name of album of around 10,000 songs. and on certain events will require to get songs of a particular album, thats why I included object reference ! what's your suggestion now ? (question edited) – user3733814 Apr 19 '15 at 02:13
  • are you looking for a layout suggestion or an sql query? – CodingInTheUK Apr 19 '15 at 02:19
  • Object oriented design to be implemented in Java – user3733814 Apr 19 '15 at 02:20
  • to be implemented in Java only ! – user3733814 Apr 19 '15 at 02:23
  • okay that is beyond my field. However, the object design i offered (actually a database layout but it will work as an object layout) will allow you to return different sets of data it just depends on what you choose to pull from the object. – CodingInTheUK Apr 19 '15 at 02:28
0
does the Object type members show redundancy?

It depends. Depends on what fields do you need in that other object type. If you only need the name while you are having the key, you can use AbstractMap.SimpleEntry<K,V>, where the K is key data type (presumably int) and V is value data type (presumably value). Otherwise, go for object relations.

And about performance thing, as long as you can avoid the looping query to database, it is already fast enough.

Fendy
  • 4,565
  • 1
  • 20
  • 25