PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
interface IUser
{
function getName();
}
class User implements IUser
{
public static function Load( $id )
{
return new User( $id );
return;
}
public function __constructs( $id )
{
return;
}
public function getName()
{
echo "Belal";
return;
}
}
$ob = User::Load( 1 );
$ob->getName();
class User
{
public static function Load( $id )
{
return new User( $id );
return;
}
public function __constructs( $id )
{
return;
}
public function getName()
{
echo "Belal";
return;
}
}
$ob = User::Load( 1 );
$ob->getName();
Interfaces are for functionality, classes are for objects.
If you want objects to be able to act a certain way you use interfaces. If one object is a more specific version of another object, use classes.
I'd say you should use class (object) when its name is a noun, and you should use interface when you may use an "*-able" to describe all of the features needed.
E.g.
User => class
Printable => interface
A common situation is to have a collection-like object (e.g. a linked list) which implements Traversable in order to be used in a foreach loop.
I'm not going to write a treatise on OOP because there are too many other people who have: http://www.google.com/search?q=interfaces+vs+classes
The articles involving Java will be some of the best: Java is very, very object-oriented.