PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

David Gardner's Blog: Why you should always use PHP interfaces

Note: This article was originally published at PHPDeveloper on 26 November 2010.
PHPDeveloper

David Gardner has a suggestion for your development that he thinks can help keep things neat and tidy - using interfaces.

This post was sparked by a very simple question from an ex-colleague: "Why bother with PHP interfaces?" The subtext here was that the classes themselves contain the interface definition (through the methods they define) and hence interfaces are not needed, particularly where there is only one class that implements a given interface.

He talks about two reasons he things that interfaces could be beneficial - they help you think about things "the right way" of planning out structure before implementation and that it makes things more "future proof" the code by forcing future elements into the same mold as the current use.