In languages like PHP and Java, there are interfaces
, which, when implemented in a class, forces it to contain the methods of this interface, just as they were declared.
Example in PHP:
<?php
interace UserInterface
{
public function getName();
}
class User implements UserInterface
{
// Se eu adiconar um parâmetro, vai gerar um erro
public function getName()
{
return $this->name;
}
}
class Scholl
{
protected $users = array();
/*
Obriga a implementação de uma classe que implemente a
interface UserInterface
*/
public function addUser(UserInterface $user)
{
$this->users[] = $user;
}
}
In Python, is there an interface or is there any standard for this?
If there are no interfaces, is there any way to "force" a method to exist in a class?
Is type induction in Python?