On Fri, 6 Jan 2006 21:38:10 +0100, "Michael" <>
wrote:
>Hi,
>
>I think my problem deals with class casting and inheritance.
Virtual functions sounds like the way to go.
>I want to deal with various Audio Formats, reading into memory for
>modification, working with it (done by different classes), and writing the
>result to disk afterwards.
>
>Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and
>MP3FileIO and AuFileIO for the In/Out operations.
>They all are inherited from the AudioFileIO class, because they all share
>common methods like readSamples, writeSamples, readHeader, writeHeader.
>Only the implementation is sometimes different.
>
>Now, I want to use them in a let's say generic way:
>
>[1]
>while(there is data)
>{
> IN.readSamples(); // using the classes mentioned above
>
> DelayEffect.work(); // modify the memory buffer(sample data)
>
> OUT.writeSamples(); // using the classes mentioned above
>}
>
>But due to different audio formats, the type of the IN and OUT variable
>depends on the desired audio format the user specifies.
>I do not want to code every time many IF-THEN-ELSE statements for checking
>the desired format and for using the proper variable.
>
>Isn't it possible to check the audio format of the incoming audio material
>at first and then casting the IN and OUT variable to the proper type of
>audio class?
>Like:
>
>IF the incoming file is a WAV, then IN = Type of WaveFileIO
>ELSE IF incoming file is a AIF, then IN = Type of AiffFileIO
>
>// then using the code fragment [1], and other code fragments like [1]
>
>
>Ciao, Michael
>
In addition to the Abstract Factory design pattern, the Strategy
pattern might serve you well for this.
--
Bob Hairgrove