using static System.Math;
Afficher(new Carré(5, '*'));
Afficher(new Triangle(7, '#'));
static void Afficher(IDessinable d)
TextWriter scribe = new StringWriter();
public interface IDessinable
void Dessiner(System.IO.TextWriter flux);
public static class ConsoleTypique
public const int LARGEUR = 80,
public static bool EstLargeurValide(int val) =>
0 <= val && val < LARGEUR;
public static bool EstHauteurValide(int val) =>
0 <= val && val < HAUTEUR;
public class SymboleNonAffichableException : Exception {}
if (Char.IsControl(value) ||
Char.IsWhiteSpace(value))
throw new SymboleNonAffichableException();
public Affichable(char sym)
public class TailleInvalideException : Exception {}
: Affichable, IDessinable
private static bool EstTailleValide(int n) =>
n < Min(ConsoleTypique.LARGEUR, ConsoleTypique.HAUTEUR);
public Carré(int n, char symbole)
throw new TailleInvalideException();
public void Dessiner(TextWriter flux)
for (int i = 1; i <= taille; ++i)
for (int j = 1; j <= taille; ++j)
: Affichable, IDessinable
private static bool EstHauteurValide(int n) =>
ConsoleTypique.EstHauteurValide(n);
public Triangle(int n, char symbole)
if (!EstHauteurValide(hauteur))
throw new TailleInvalideException();
public void Dessiner(TextWriter flux)
for (int i = 1; i <= hauteur; ++i)
for (int j = 1; j <= i; ++j)