Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created December 10, 2020 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Riduidel/7b0ba17affe0ea57211b3cc78e9b71c7 to your computer and use it in GitHub Desktop.
Save Riduidel/7b0ba17affe0ea57211b3cc78e9b71c7 to your computer and use it in GitHub Desktop.
Visitor -2 - Main avec interface
import java.util.Arrays;
import java.util.List;
class Feuille implements Affichable {
public String montrerFeuille() { return "🍃"; }
@Override public String afficher() { return montrerFeuille(); }
}
class Fleur implements Affichable {
public String afficherFleur() { return "🌺"; }
@Override public String afficher() { return afficherFleur(); }
}
interface Affichable {
public String afficher();
}
public class Main {
public static void main(String[] args) {
List<Affichable> affichables = Arrays.asList(new Feuille(), new Fleur());
for (Affichable affichable : affichables) {
System.out.println(affichable.afficher());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment