In java, you can have composite pattern easily using interface, like this:
Animal[] animals = new Animal[] { new Elephant(), new Cow(), new Cat() };
for(Animal currAnimal : animals) {
// Do the stuff here
}
Now, I want to have the same thing for serial RX interrupt in AVR. Something like this:
ISR(USART0_RX_vect) {
uint8_t data = UDR0;
for(InterruptHandler currHandler: interruptHandlers) {
currHandler.handle(data);
}
}
By that way, I can chain the interrupt handler easily. Of course, mixing C and Java in C-compiler won’t be OK for AVR-GCC. But I found out some way to do the similar thing in C.