Re: Need Help with design of class hierarchy
On 3/11/2015 2:32 PM, sdubak4@gmail.com wrote:
Hi, I am having a difficult time figuringout how I'm going to design my
base and derived classes for a specific project.
What I'm looking to do is come up with a design for an efficient OO class design
to represent songs in an Artists catalog. Songs at te lowest level. Then Discs
becasue each song is contained on a disc within a particular release by the
artist. And there are multiple releases. And multiple artists.
Here's a very simplified example of what I've been thinking of. Hopefully this
will be readable and understandable to everyone:
class Song // every song has it's own class
string &name; // full path to song on disk.
virtual GetRelease(); // With a pointer to any Song class, one
virtual WHAT GetRelease() ? What's the return type?
virtual GetArtist(); // could obtain the Disc, Release and
virtual GetFullPath(); / /Artist associated with that song.
class Disc : Song // Each Release has at least 1 disc
virtual int GetDiscNumber();
'Disc' derives from 'Song'? So a 'Disc' IS-A 'Song'? I am not sure I
actually agree. Shouldn't 'Disc' be actually a container of 'Songs'?
class Release : Song
virtual string& GetFullPath();
virtual string& GetRelease(); // Get name of the Release
class Artist : Release
virtual string& GetArtist();
With the above simplistic design, if you have pointer to a Song class, you can
get the Artist name and the name of the Disc, Release and Artist. What I don't
like about it though is that to represent an entire I would need name instances
of the Artist class. I would need an instance of the artist class for every song
on that particular Release. Then to represent the Artists entire music
collection, I would need an Artist class for every song in the artists catalog.
The same is true for all classes up the hierarchy. An artist has many releases
An alternative.
class Song
string &name;
class Disc
array<Song*> songs;
class Release
array<Disc*> discs;
class Artist
array<Release*> releases;
What I fdon't like about the above design is that there's not any OO'ness about
it. array's could be lists, doesn't matter. If I have a pointer to a Song class,
I don't have any oter information about the song. I can't get the Artist name,
the release it came from, etc ... But what's good about it, as compared to the
first example, is I only have 1 instance of the Artist class for each and every
artist.
Looking for suggestions on how one would go about designed a good class
hierarchy to represent the music of a particular recording artist.
Any suggestion greatly appreciated.
OK, here is a suggestion: start from the right end. What you need is a
system that *uses* your objects. From their *use* you can distill their
*interface*. Once you have the interface, the class design becomes a
walk in the park. So, start with describing how your objects are going
to be *used*.
And it doesn't really matter what language you are going to use to
implement your system. Don't try designing with any specific language
in mind. Forget 'virtual' or 'array<>' or "pointer to". Use
pseudo-code to describe the relationships. Translating your pseudo-code
into any language of your choice is not important to the design, really.
What if tomorrow you decide to make a prototype of your system in Python?
I probably didn't understand the entity relationships in your
explanation, so excuse my reaction. I hope you will see the problem
from my POV.
Good luck.
V
--
I do not respond to top-posted replies, please don't ask