I have a number of classes (and interfaces) which 'code to an interface'interface File {    ...}interface FileConverter {    public function convert(File $file); //coding to an interface    public function success($message);    public function failure($message);}I feel I can make the FileConverter interface even more generic by removing the File class type-hint in this interface to allow conversion between strings, arrays etc rather than just classes that implement File;interface Converter {    public function convert($input);    public function success($message);    public function failure($message);}However, if I do this, I feel I loose the 'coding to an interface' aspect - even though none of my classes directly use the FileConverter interface. Is this a wise choice or should I create a different interface? ie;interface StringConverter {    public function convert(string $string); //PHP 7    public function success($message);    public function failure($message);}
Coding to an interface vs more generic interfaces
php;interfaces
All objects implementing a particular interface must not only define methods with matching signatures, but also with matching semantics.Meaning: you should be able to replace object A which implements I with object B which imolements I and still have things work.If in your case both A and B define convert(), but A will only work with a string and otherwise crash or return something weird, and B can only work with files, thab they are not substituable, and do not actually implement the same interface.(It just seems they do, because a dynamically typed language such as PHP doesn't force you to define the types in the method signature. The equivalent Java methods, for example, would be Something convert(String s) and Something convert(File f). Now it's clear that they're not the same interface.I'm not saying you should always use type hinting in PHP. I'm saying that implementing an interface means matching particular semantics, and not just a signature.