Interfaces are useful tools for systems architects and are often used to prototype an Application Programming Interface (API). Interfaces don't contain actual code, but can contain names of methods as well as method signatures.
Methods identified by the interface cannot contain actual code implementations. You can, however, specify the data types of method arguments.
In this example,
ConnectionAwareInterface
identifies a method,setConnection()
, which requires an instance ofConnection
as an argument:interface ConnectionAwareInterface { public function setConnection(Connection $connection); }
To use the interface, add the keyword
implements
after the open line that defines the class. We have defined two classes,CountryList
andCustomerList
, both of which require access to theConnection
class via a method,setConnection()
. In order to identify this dependency, both classes implement...