« Patrons de conception/Double-dispatch » : différence entre les versions

Contenu supprimé Contenu ajouté
DannyS712 (discussion | contributions)
m <source> -> <syntaxhighlight> (phab:T237267)
Aucun résumé des modifications
Ligne 35 :
System.out.println(book.toString()); // SimpleObject.toString
</syntaxhighlight>
 
Affiche :
a simple book
Ligne 80 ⟶ 81 :
disp.display(book, card); // -> SimpleDisplay.display(Object, Object)
</syntaxhighlight>
 
Affiche :
A simple display for object (a simple book) and object (a simple card)
 
L'exemple précédent démontre que le langage Java ne permet pas nativement le '''multiple-dispatch'''. Dans le cas contraire, la méthode <syntaxhighlight enclose="none" lang="java">SimpleDisplay.display(SimpleObject, SimpleObject)</syntaxhighlight> aurait été appelée et l'affichage aurait été le suivant :
A simple display for simple object (a simple book) and simple object (a simple card)
Ligne 140 ⟶ 143 :
book.display(disp); // SimpleObject.display(Display) -> SimpleDisplay.display(SimpleObject)
</syntaxhighlight>
 
Affiche :
A simple display for simple object (a simple book)