Interesting polymorphic problem.

BlitzMax Forums/BlitzMax Programming/Interesting polymorphic problem.

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.


If I use a calculator as an example...

The caclulator has a display. Tat display is physically capable of drawing the numbers 0 thru 9.

The calculator has a CPU. The CPU knows how to take input, and tell the display what numbers to display, but it cannot alter the display to be capalbe of showing letters.

The buttons know how to take input from the user and provide that input to the CPU. But the buttons can't change how the CPU's SINE function works. If the CPU's SINE function takes radians normally, and you need it to take degrees, you don't tell the buttons to alter the CPU's sine function, you directly alter the CPU itself.



Now take your example and think of about displaying the numbers using an LCD and alternatively LEDs (not in terms of using different bitmaps, but real different ways of displaying them, be it hardware or f.i. using bitmaps for LCDs and vector shapes for LEDs).

If you give the CPU an LCDDisplay type and use that, you cannot change the behaviour without altering the CPU code - if you use an abstract CalcDisplay just defining the interface and implement derived types LCDDisplay and LEDDisplay you can use instances of both and just hand them to the CPU as a CalcDisplay because the CPU really isn't interested in the concrete type of display.