- The Interfaces are abstract classes, which was declared but not defined.
- we can not create object of Interfaces.
- To use interfaces, we use "implements" keyword.
- Interfaces have empty functions which you have to defined during the implement.
- You have to defined all the functions during the implements.
- Interfaces are 100% blueprint that tell what function you must defined.
- We can implements one or more class during in-heritance.
Following are the Example of Interfaces
interface iTemplate { public function setVariable($name, $var); public function getHtml($template); } // Implement the interface // This will work class Template implements iTemplate { private $vars = array(); public function setVariable($name, $var) { $this->vars[$name] = $var; } public function getHtml($template) { foreach($this->vars as $name => $value) { $template = str_replace('{' . $name . '}', $value, $template); } return $template; } }
No comments:
Post a Comment