Created
December 10, 2020 06:26
-
-
Save Riduidel/5b6f48453524afb50b750397155320d3 to your computer and use it in GitHub Desktop.
Visitor - 1 - main simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
class Feuille { | |
public String montrerFeuille() { return "🍃"; } | |
} | |
class Fleur { | |
public String afficherFleur() { return "🌺"; } | |
} | |
public class Main { | |
public static void main(String[] args) { | |
List<Object> visitables = Arrays.asList(new Feuille(), new Fleur()); | |
for (Object v : visitables) { | |
if (v instanceof Feuille) { | |
Feuille f = (Feuille) v; | |
System.out.println(f.montrerFeuille()); | |
} else if (v instanceof Fleur) { | |
Fleur f = (Fleur) v; | |
System.out.println(f.afficherFleur()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment