OOP, include files and Arduino

Hello,

Is there any solution if an Arduino libray is used and if there are several include files which use one instance of the library?

What is the better solution:

One file pair (.cpp/.h) instancing the library and serveral funtions that are calling the libraries functions (->to have access to the instance of the library and the functions in it)?

Is it better to instance the library in the *.ino file and forget all the other include files?

Is there a better way to do so?

Should everything be written in OOP?

What about memory usage?

Please give me an answer!

Yours,
Stefan

Please give me an answer!

Please ask a concrete question.

Is there any solution if an Arduino libray is used and if there are several include files which use one instance of the library?

Yes. Some specifics would be useful.

One file pair (.cpp/.h) instancing the library and serveral funtions that are calling the libraries functions (->to have access to the instance of the library and the functions in it)?

Maybe. Or maybe not.

Is it better to instance the library in the *.ino file and forget all the other include files?

Maybe. Or maybe not.

Is there a better way to do so?

A better way to do what?

Should everything be written in OOP?

Yes. Except the parts that don't need to be.

What about memory usage?

What about it? It's best to minimize it.

(Paul is having a good day today :slight_smile: )

Unfortunatly your qustion is similar to asking if it better to use string or adhesive tape to wrap a package for sending with the post. Thus the answer : It depends, it is a matter of taste, and both work for most cases. A few edge cases might prefer one over the other.

You can always write a large program as a single file. It is just for your editing convinience you may split it. There is no need to put a class in its own cpp/h pair unless you will use it for several different project, ie it is a "Module" you reuse.

The compile/link is quite good at elliminating unused code, so you could have all your "library"-classes in one file. Only the ones actually used are included in the final image (but they do get compiled)

Beware that the Arduino does some "mangling" of the source code (to help newbies by - f.ex. - declaring prototypes so the order of using and defining a function is irrelevant) and thus some modluar stuf fof C/C++ works slightly different in the Arduino enviroment with multiple files.