arduino / arduino/Arduino

Use 'protected' and not 'private' in core and libraries

Open
#1,627 5 comments 0 reactions 1 assignee Claimed by @cmaglie View on GitHub
Component: Core feature request Library: Other
Dominant language
Java
Stars
14.6k
Forks
7k
PR merge metrics
No merged PRs in 30d

Description

Currently, with widespread use of 'private' in all of the core classes and libraries, it can be extremely difficult to make minor changes to a class implementation without (literally) copying the entire class implementation (and possibly all of the utility classes), re-naming everything, and then applying your changes to the new code. Wouldn't it be much SIMPLER if you could DERIVE your own class implementation (maybe override specific functions, or provide NEW ones that are application specfic) and access all of the (currently 'private') members with your 'specialized' or 'improved' version in order to implement it?

I had to make changes to HardwareSerial to improve 'send' performance at 115kbaud (it was only running at around 8k/sec instead of >10k/sec with an 8mhz clock, and I got it up to 9.7k/sec with my mods). I had to make copies of the appropriate core files and change the class name, and THEN place them in their own directory in 'sketchbook/libraries' and change the '#include' line to use my version of HardwareSerial. HOWEVER, it would have been MUCH easier if I could have simply DERIVED my own class, something like:

class MyHardwareSerial : public HardwareSerial

and then declared 'MySerial' as an external of type 'MyHardwareSerial' and used that instead of 'Serial'. For this to have worked at all, you would need to declare the 'private' members as 'protected' in HardwareSerial. That is the point.

Please make it easier to derive our own class implementations from the core classes and the supplied libraries. Please use 'protected' instead of 'private'. You can specifically tweek out the libraries for specific hardware that way, or perhaps combine the functionality of 2 classes into a single function to greatly improve performance. THIS is the kind of flexibility open source is supposed to provide. Using 'private' for class members GETS IN THE WAY of end-user flexibility.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.