I have a collection of view objects. Each one of these objects must 100% implement the following interface:
/**
* Interface that each base ViewBlock object must implement.
*/
interface ViewBlockInterface extends CosmeticInformationInterface, ScriptInterface
{
public function getBlockName();
}
Now, here's 2 interfaces that some of these objects might choose to implement:
use Interfaces\StyleInterface;
use TemplateInterface;
As such, an object must be of type ViewBlockInterface
but can be either StyleInterface
or TemplateInterface
or both, meaning that we can potentially have a case where an object is all 3 at the same time.
Here's my problem: in my generator (that ingests all these objects), I have no clean way of handling each interface. I have to rely on code like:
if( $object instanceof ScriptInterface) {
//Do some stuff that should only happen if this check passes.
}
..
..
//Do the same thing for N interfaces
Is there no pattern, way of architecturing my objects to escape this?
I can re-write this any way I want without a problem.
function execute()
in the interface that requires to implement the logic in the clients and then in your generator you just call...->execute();
– Did Jan 9 '20 at 9:10