Question about heritage.

Posted 27 October 2018 - 10:19 AM

Hi!
I'm trying to create a library of artists where one artist has one or more albums and each album has one or more musics.
So I created the following classes and in my main method given a music I try to get the name of the album in wich its belongs and the author(Artist).
And I do that, but when I try to get the number of fans of the artist I get always 0.

I think is because the music object is not the same as artist even the music object has an artist. But how can i fix that?

I think I could do that passing this number(number of fans) using constructor. But if I have many other attributes in Artist as well as Album.
Would be a huge amount of arguments in the Music contructor.

Replies To: Question about heritage.

Re: Question about heritage.

Posted 27 October 2018 - 10:28 AM

An aside - Albums have _songs_ or _tracks_ not musics. You would also probably want to keep track of the track number.

You should think where you are tracking the fans. Do you want that in the album level.. or artist level. Album level may have multiple same people liking albums so adding them up for artist doesn't make sense.

Re: Question about heritage.

I think it's more like an Album has 1..n Artists because there are collaborations, and there has to be at least one artist. For example, consider Slash's album: https://en.wikipedia...)#Track_listing

Every song has a different vocalist, and they are all artists. So, the entire album could be considered to have 13+slash=14 artists on one album.

So, the Album might contain a collection of Artists, but then which artist goes to which track? Instead, An album should contain a collection of Tracks, and a Track should have a collection of Artists.

Album HAS Tracks HAS Artists. Nothing IS anything else.

EDIT:

Actually, I would introduce Group or Band or something. These would be core members attributed to an album for every track. Album HAS Band and a Band HAS Artists. Then each Track HAS Artists as well - these are the one-off collaborators, etc.

Re: Question about heritage.

Posted 29 October 2018 - 06:38 AM

I wouldn't personally use interfaces. Interfaces are for when things do stuff. You have a situation where things are stuff mainly.

Have said that, you need to design your software on what you want it to do. For instance, it might not be necessary to model the relationship from AlbumtoArtist so that would simplify your object relationships.

A piece of software is written to accomplish tasks. What are your tasks?

Re: Question about heritage.

Music seems to be over-abstract to no good effect. Just Song might do, or Track. Actually the latter is normally used of albums

Artist <- Album <- Track is a reasonable structure (an artist has [0..many] albums, an album has [0..many] tracks)
However, this assumes that a track is on an album, which might not make sense in today's world. People release tracks without albums, and forcing them to associate a track with an album might not accord with their intention.
A more subtle issue, which plagues most music players, is that a track can appear on multiple albums - for example, it shows up on the original release, on the single, on the EP, on the greatest hits collection. Also, a different track with the same name shows up on the live album and maybe on the fan bootleg, and a similar track shows up as a remix somewhere - and I'm sure we can come up with other cases, for example a different version of the same song appears on some other artist's album as a cover tune, or the track shows up in an anthology collection of multiple artists, etc., etc.

So we're into a data modeling problem, and it's probably worth spending a little while thinking carefully about exactly what parts of this problem matter to you, and which parts you're willing to get wrong.

For example, most music players are completely incapable of linking two different versions of the same song, which is understandable (it's not obvious how that would be executed) but also frustrating to the listener who wants to find, say, someone else's cover of a certain Bob Dylan song, knowing only that the song is Tombstone Blues. They generally can go by the title, but that's bothersome if another song exists with the same title. This gets you into partial-match problems, for example someone looking for "Let It Be" by the Beatles will likely find themselves having to filter out "Let It Be Me" by the Indigo Girls.
If this is a problem you care about, you have to build your data model to address it. If you decide not to care about this problem, it's best to make that an intentional decision rather than an accidental failure of foresight.

Re: Question about heritage.

Posted 30 October 2018 - 07:27 AM

People.
Thank you very much for your help. I have to say that you have extrapolated the problem a little. But ok you guys tried to help. The problem was as simple as the one I originally posted. We have to make a music player simulator. The app will not actually play a song, but we have to simulate that.

So we have:
SearchActivity: Search where you have to type something. Could be an artist, album or song.

ArtistActivity: Artist info visualization.
It shows some information about the artist: fans, number of albums, year they started to play and the list of all albums.

AlbumActivity: Album info visualization.
When you click on an album and then you see the name of the artist all tracks and some other infos: year, fans(here too I don't know why), number of tracks.

PlayerActivity: The player itself.
You see the artist, album, name of track, time, year(probably the year of the album)...

As you can see in player visualization I have to show informations not only about the song but the album and artist too. And the album visualization I have to show some artist information as well. Thats why I tried originally heritage design. Because when I send an Artist object through Intent to player activity by heritage I could know which album it belongs to and which artist. I cannot send more than one object.

I posted here because is a java design class problem not a android problem.