Design question

Started by
2 comments, last by kuphryn 17 years, 8 months ago
I am making a sound synthesizer, so I want to create different types of waves for notes. Such as: sin wave, trianhle waves, etc. In short, I did the following:

class SynthesizerTypeCreator: public BaseClass {
	public:
		virtual Real SynthSample (Real _Amplitude, Real _Position)=0;
};

class SquareSynthesizer: public SynthesizerTypeCreator {
	public:
		Real SynthSample (Real _Amplitude, Real _Position);
};

class SinSynthesizer: public SynthesizerTypeCreator {
	public:
		Real SynthSample (Real _Amplitude, Real _Position);
};

class SoundSynthesizer: public BaseClass {
	public:
		void CreateWave (MusicalNote & _MNote, Real _StartTime, SoundContainer & _SContainer, SynthesizerTypeCreator * _pTypeCreator);
	private:
};

Is this a good way to solve this problem? or can the pointer cause some bugs? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
It's not a very good idea to have a BaseClass.

The name SynthesizerTypeCreator doesn't describe very well what it does. I would rather call it Synthesizer.

Your derived classes (SquareSynthesizer and SinSynthesizer) should have constructors that take whatever parameters they need (in those two cases, a frequency will do) and data members to store them.

I would also write a factory that would be able to construct any type of Synthesizer from a description (probably a text string). That way the rest of the code will not see the derived classes and you can add new Synthesizers without even recompiling the rest of the program.

Why is your rating 0? What did you do?
Quote:Original post by alvaro
It's not a very good idea to have a BaseClass.

The name SynthesizerTypeCreator doesn't describe very well what it does. I would rather call it Synthesizer.

Your derived classes (SquareSynthesizer and SinSynthesizer) should have constructors that take whatever parameters they need (in those two cases, a frequency will do) and data members to store them.

I would also write a factory that would be able to construct any type of Synthesizer from a description (probably a text string). That way the rest of the code will not see the derived classes and you can add new Synthesizers without even recompiling the rest of the program.

Why is your rating 0? What did you do?

These are good ideas, but I think it is a bit overkill.
I just feared there might be a bug for using a pointer instead of a reference, but I dont think I can replace the pointer with a reference in this case.
Why I have a zero rating? perhaps an art statement?

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
object factory is one good solution

last class should not be derived from base

Kuphryn

This topic is closed to new replies.

Advertisement