← back to code snippets


Using an interface

Posted on August 27th, 2014 by Graeme

Define The Interface

interface interface_name
{ public function function_name(arguments) }

As you can see, the interface contains no implementation, you just list all the methods and arguments that have to be implemented by classes using the interface.

Create The Implementation

class class_name implements interface_name
{
public function function_name(arguments)
{ //implementation of interface goes in here } }

Simple as that. If the implementing class doesn’t implement all the defined methods, it won’t compile.

See Source: nettuts