The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface
), I check if these certain objects have certain methods and based on that, do stuff, if not, just skip that object in the array.
if( method_exists( $loaded_module, 'getBlockViewStylesFilePath' ) ) {
//logic with $loaded_module->getBlockViewStylesFilePath()
}
The problem with this approach is that, unless you read the documentation (which, of course, almost no one does), you won't know about it. I don't want to throw errors, but in my interface, ViewBlockInterface
, I don't want to define these, because it's not necessary that every block have CSS / scripts attached to it.
In short, I want the developer to know that if he defines these functions, stuff will happen, but it's not required to have them. I also believe that the scope of this sub-system is so small that I don't want to create 4+ interfaces just for this.
What can I do here?