This is probably a bit of an open question, and possibly one that could be answered on stack overflow however I thought given the number of people here experienced in embedded C++ it might be an ok place to start.
My background in embedded programming is in C, at university there wasn’t a lot of emphasis on OO for embedded although I did have some background in Java OO programming.
Recently I’ve found my programming skills pushed to the limits as it seems most text books don’t really talk about how to structure large programs. One of these issues for me is when to bother putting a ‘library’ or ‘module’ into a class or when to simply use the old method of C which was to declare all public functions in the header file.
I notice the majority of libraries available in Particle build use the C++ class methodology, I understand one of the benefits of this is to provide clarity in terms of restricted access i.e.declaring members private/public/protected. What other significant reasons are there for this?
At the moment I’m trying to figure out how to create a class (if it should be a class) of functions specific to communicating with an external piece of hardware. There will be multiple cpp files requiring access to these functions, hence by definition it will need to be a ‘global’ object. In this case, should each cpp file that needs access contain a separate constructor? To me this seems non-intuitive as the class describes an implementation to communicate with a single piece of hardware and hence only one object should be required. This has taken me to the concept of the ‘Singleton Pattern’ which delves even further into programming philosophy.
I suppose where I’m coming from is, OO programming was always described to me in terms of abstract concepts such as creating a ‘student’ object where you may want to do things like view age, change grades etc. or create ‘new’ students. This whole concept doesn’t make as much sense to me when viewed from an embedded world, where classes and objects in this context seem to very often only be used once.
If anyone could shine some light on this it would be hugely appreciated, I have spent considerable time trying to enlighten myself on other forums but I’m not quite there yet!