Skip to content

Strategy

Problématique

Comment faciliter l’utilisation d’algorithme différents dans une application?

Solution

// Interface de l'algorithme
interface CryptageInterface
{
	public function crypt($data) ;
}
 
class CryptageFake implements CryptageInterface
{
	public function crypt($data)
	{
		return $data ;
	}
}
 
class CryptageMd5 implements CryptageInterface
{
	public function crypt($data)
	{
		return md5($data) ;
	}
}