Skip to main content
added 21 characters in body; edited tags
Source Link
coolpasta
  • 641
  • 5
  • 16

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?

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?

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?

Source Link
coolpasta
  • 641
  • 5
  • 16

Can I make other developers aware that they can define certain functions for extra-functionality even if they're not required?

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?