I am trying to write an iterator for a hierarchy of classes that collectively make up the components of a song. All classes are implementations of the abstract MusicComponent base class and inherit a getChildren() function. The abstract MusicTime subclass knows the actual note/chord to play, and all its implementations (e.g. quaver, crotchet) return null for getChildren().
The other components are MusicComponent which holds a collection of MusicTimes e.g. a bar at a time, and Section which holds the MusicComponents. Song holds the Sections that make up the song e.g. verses, choruses, sections with different tempos/time signatures.
What I need is an iterator that will iterate through all Sections in a Song, then all MusicComponents in the Section and only when it finds a MusicTime descendant, play the note for the length of time based on its note type, and the time signature and tempo of its containing Section.
Sorry if too much info, but was the only way I could explain what I'm trying to do. So do I need to handle this with a stack, recording which MusicComponents I've visted or is there a way to do this just using recursion?