|
You can have a set of methods declared in an entity called interface. Don’t get me wrong, in the interface thing there is only the method declaration, not the actual code. Now, any class that wants to implement a certain interface has to provide the methods declared within the interface. Fairly obscure, why to have a method declaration outside a class definition and then the actual method code inside the class? Well it’s not very obvious but, the idea is to have a generic definition of what a method (or a class) should provide. Thus, if you have large portions of code using a method and the method itself requires changes for some reason, you can ensure it will comply with its initial external definition, the interface. It looks like object oriented programming people tried to cover their backs here with one of the inherent issues of object oriented design, oops sorry shouldn’t mention the war. Well, here is the code for it nevertheless don’t expect to see something very interesting here. <? interface printint { public function printuser(); } class User implements printint { var $name; function __construct($newname) { $this->name = $newname; } function printuser () { print $this->name; } } class Admin extends User { var $mobile; function __construct($newname, $newmobile) { $this->name = $newname; $this->mobile = $newmobile; } } $harris = new Admin("Steve Harris","9600888888"); $harris->printuser(); ?> |