oop - PHP Working with Interfaces some advice needed
I have just discovered the joys of interfaces. I always knew they existed but being able to check if the class is an instanceof an interface has allowed me to add a nice amount of flexibility and the around the various objects that i'm using.
i realise that i can have any number of interfaces and i've read that it might be best to not have too many. so i'm curious as to how much i should interface.
forexample i want to add things like Interface_Images that has functions and calls for hasImages, getImages etc... that way in my views i can simply do
if(object instanceof Interface_Images) {
// do something
} else {
if(object->hasImages()) {
// do something else
}
}
is it worth me doing this?
Answer
Solution:
Follow Interface segregation principle and use so many as you need.
Also use is_callable for checking methods if you cannot use iterfaces.