(I apologize for the additional post, but I forgot to crosspost in the
original)
For a hobbyist project, I'm writing a music composer, and I really
want to make it object-oriented because the data really lends itself
to OOP for reasons I'll explain later. The only problem is that,
while I'm a competent Pascal programmer, I've never done OOP before.
My environment is Turbo Pascal 7.0. Before I lay out the details, I
want to stress this is not a homework assignment :-) I am not asking
for code, just the normal, best-practices way to do what I want to
accomplish.
I thought of creating a "song" object with the ability to enter notes,
save/load the song data, etc because it makes perfect sense; the
methods can validate the data and generally abstract the song. But
the song needs to play, and that's where I get stuck on the proper way
to program in OOP to access the song data. Should I:
- Make a new "player" object that inherits the song object (so that it
can directly reference the song data structures)?
- Make a new "player" object that calls the song object's methods to
pass the data back and forth?
- Have the song object pass a pointer to the note data to be accessed
by the player object? (that seems like it's defeating the whole
purpose of OOP)
- Build the playback routines directly into the song object, so that I
have a single object with a gazillion methods?
The program needs to be able to play the song, not only for one
particular output device, but several. That means the playback
routines need to be VIRTUAL so that I can replace them with methods
for additional sound devices as I code them. It is that requirement
that has me confused about the proper direction to take.
I was leaning toward this:
A song object;
a player object that inherits the song object and contains only
generic VIRTUAL playback methods;
a device-specific object that replaces the virtual methods with
methods for that device's hardware.
I figure that way I can get direct access to the song's data
structures without "exposing them to the outside", and I can keep
building on previous code as necessary.
Does that sound like the right way to go, or am I barking up the wrong
tree?


|