As you know, we can use Interface and Implements in PHP5.
I used Interface in Java SE but It’s useful there only for listener or … but I can’t find any benefit of Interface in PHP5.
Please help me understand benefits of Interface in PHP5.
Thanks for your advice.
In an object oriented language you can’t deny the benefits of Interface, there are hundreds of benefits.
Let me give you an example for Dummies:
I assume you use MVC and Ajax. And during every
focusoutofinputyou pass theinputvalue to the server as well as a model name which is stored in thedata-model(custom) attribute.Now when you lost focus from the input it sends data to server like this
In the server you just call the model name which is received from ajax request. Something like this
Here the value of
$a_modelvaries, so you can’t make sure that this model would haveupdate()method. Here interface comes into play. Interface forces all the implemented models(classes) to have anupdate()method so that you can run above code unconditionally.Hope this makes sense.