How OOPs concept are useful in Embedded System

Thread Starter

Fanfire174

Joined Mar 13, 2018
219
Hello.

I have seen we mostly use c language for embedded system. I am looking for real time example in Embedded Systems.

Can anybody tell me a situation that would make me use of OOP features for Embedded Systems?

Thanks.
 

Papabravo

Joined Feb 24, 2006
12,563
In a career spanning half a century in embedded systems, I don't think I have seen or even heard of one. That doesn't mean there isn't one. Good luck in your search.
 

nsaspook

Joined Aug 27, 2009
6,506
Hello.

I have seen we mostly use c language for embedded system. I am looking for real time example in Embedded Systems.

Can anybody tell me a situation that would make me use of OOP features for Embedded Systems?

Thanks.
The problem with saying OOP features is that OOP today includes things that traditionally were under the hood of structured programming. Any possible OOP concept (classes, encapsulation, inheritance and polymorphism) can be programmed in ASM with the proper style of structured programming. OOP languages are designed with a specific structured programming style (a software design pattern) in the language to provide language enforced compile time debugging of common structured programming issues instead of a programming expert doing it manually. The majority of small Embedded Systems don't really need this OOP language crutch to help enforce program correctness but most use structured programming OOP features in the function design and data flow.

This is the problem with going all in with OOP in embedded programming.

“ You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.”
Joe Armstrong, the creator of the ERLANG language


With C you can solve the problem without all of the monkeys, bananas, and jungles of OOP. ;)

Why is C such a rude language?
cos it has no class
 
Last edited:

MrSoftware

Joined Oct 29, 2013
1,576
I only pick this example because I happened to be looking at the code the other day, but read the HID Keyboard implementation library for Arduino. At the bottom is PluggableUSB class, which is used by HID class, which is used by Keyboard class. This is a great way to implement re-usable layers. PluggableUSB class can be used by not only HID class, but any other class that might need pluggable USB functionality. Similarly HID class can be used by any class that needs to implement HID, such as clases to implement a keyboard such as this example, a mouse, touch pad, bar code scanner, etc.. I believe this will run on the Arduino UNO which uses an ATmega328P 8-bit processor. Could this have been done without using C++? Absolutely, but using C++ sure makes it easier to read, maintain and re-use with no obvious negatives for the intended use.
 

nsaspook

Joined Aug 27, 2009
6,506
All of that is great and good for connecting X to Y in any language using handles but it does little or nothing to solve a actual unique program functional problem (abstracting to a programming language the fine-grain detail of some physics driven engineering problem solved by the embedded system) with the data from those classes.

ganesha-abstract-painting-500x500.jpg
Too much abstraction can be hard to understand as Simplified Complexity is IMO, an oxymoron.

What one is better?

circle.grow(3)
or
grow(circle,3)

Objects and methods are syntax sugar for structs and procedures.
 
Last edited:

WBahn

Joined Mar 31, 2012
24,854
Hello.

I have seen we mostly use c language for embedded system. I am looking for real time example in Embedded Systems.

Can anybody tell me a situation that would make me use of OOP features for Embedded Systems?

Thanks.
About the only thing that would MAKE you use OOP features would be a decree from above, be it company policy, project management, or customer specifications.

Now, if you were to ask about why you might CHOOSE to use OOP features, that's a different question entirely.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
219
C++ is object oriented language. It can be used in real time system and It can be use to make device driver.

A class in C++ is a user defined type with keyword class that has data and functions as its members whose access is governed by the three access specifiers private, protected or public The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class

I am aware of class in c++ language. Can you give me some real time examples of classes in embedded system.
 

Ian Rogers

Joined Dec 12, 2012
666
Just because C++ can handle data structures such as classes, doesn't mean you have to... I have used a C++ compiler to compile C code many times.... Alot of the old programs written in C have to be recompiled to run on Win7 platforms and above.. Same code, new compiler!!
 

ErnieM

Joined Apr 24, 2011
8,007
I am aware of class in c++ language. Can you give me some real time examples of classes in embedded system.
I actually used a class in my last project which is a four channel RGBW LED controller. I used a class to encapsulate all the data and methods to control a channel. Pin numbers, timers, settings for R G B and W levels all part of the class.

I was using a $7 ESP32 controller which has megs of memory.
 
Top