Serial base class

I've been looking into Arduino (and Teensy) programming recently and tried to write a sketch which might be used on both. What I stumbled upon was how to do the debug output (or generally speaking: serial communication). For the Arduino I would use the Serial class, while the default Serial object for the Teensy is the HardwareSerial class. If I want to do serial communication using TX/RX pins there are the SoftwareSerial and NewSoftwareSerial classes.

Currently I am using some crude #ifdef logic to switch between different approaches.

Design-wise I would prefer a concept which uses an interface or virtual base class for all Serial like communication implementations.

Would it be a reasonable request to change the core class Serial so that it is based an such a virtual base class, which could be used by other projects (e.g. such as NewSoftwareSerial)?

The Serial variable is an instance of the HardwareSerial class too ( standard Arduino core ). It derives the Stream library which in turn derives the Print class.

Have you tried it? (using the variable Serial)

Design-wise I would prefer a concept which uses an interface or virtual base class for all Serial like communication implementations

Just #include <streaming.h>
Instantiate the port as mySerial
Then use mySerial << “Hello World\n\r” << “I am alive!!!” ;

http://arduiniana.org/libraries/streaming/

Ray