samedi 16 avril 2016

Array of objects: how to ensure interface

Given an object:

class MyObject implements MyInterface
{
   public function testMethod() {

   }
}

If there will be another class what uses an array of objects that implment MyInterface like this:

class Consumer
{
    public function __construct(array $myInterfaces)
    {
         foreach($myInterfaces as $myI) {
            $myI->testMethod();
         }
    }

}

How can i make my program design robust where i know that I can safely call testMethod() against the array elements?

Aucun commentaire:

Enregistrer un commentaire