unknown
2006.06.20, 04:35 PM
For example If I wanted to write a complex number class, and of course I want to deal with normal and polar forms.
I've got a list of functions I can do in normal form, and another list I can do in polar form.
I would want it to call the function if it can in the form its currently in, but convert it to the other form and call the function if it can't.
so that means I suppose ill want ComplexNumber, and then PolarComplexNumber which is a subclass of ComplexNumber, as would be NormalComplexNumber.
but how can my instance of ComplexNumber (which is either a PolarComplexNumber or NormalComplexNumber) know what functions it can and cant call?
How can ComplexNumber convert itself?
What other ways could there be to do this?
I've got a list of functions I can do in normal form, and another list I can do in polar form.
I would want it to call the function if it can in the form its currently in, but convert it to the other form and call the function if it can't.
so that means I suppose ill want ComplexNumber, and then PolarComplexNumber which is a subclass of ComplexNumber, as would be NormalComplexNumber.
but how can my instance of ComplexNumber (which is either a PolarComplexNumber or NormalComplexNumber) know what functions it can and cant call?
How can ComplexNumber convert itself?
What other ways could there be to do this?