dependency injection in Arduino
<p>I've started working with Arduino and I want to do a time share system so I do not use the delay command. </p>

<p>I have a problem when I try to register objects that inherit from another.</p>

<p>Here I have a test code that should show in the terminal: "Wow wow Miuau miuau ..."</p>

<p>I have doubts when I try to create an Interface and how do I declare the register () function so that Cat and Dog objects can be entered in the Animal type Array.</p>

<p>The following code is only to show the problem:</p>

<pre><code>class Animal {
  public:
    void message() {

    }
};

class Dog : public Animal {
  public:
  void message() {
    Serial.println("Guau guau");
  }
};

class Cat : public Animal {
  public:
  void message() {
    Serial.println("Miau miau ");
  }
};

class Multiplex {
  private:
    int index = 0;
    Animal objects[5];
  public:

  void register(Animal object) {
    objects[index] = object;
    index++;  
  }

  void go() {
    for(int i = 0;i&lt;index;i++) {
      objects[i].message();
    }
  }

};

Dog dog;
Cat cat;
Multiplex multiplex;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  multiplex.register(dog);
  multiplex.register(cat);

}

void loop() {
  // put your main code here, to run repeatedly:
  multiplex.go();
  delay(1000);

}
</code></pre>

<p>Any help is welcome ...</p>

<p>Thanks and sorry for my english.</p>