Skip to content

Instantly share code, notes, and snippets.

@marc-x-andre
Created November 9, 2017 14:21
Show Gist options
  • Save marc-x-andre/c2e12e83f48df27e18beb912010f8502 to your computer and use it in GitHub Desktop.
Save marc-x-andre/c2e12e83f48df27e18beb912010f8502 to your computer and use it in GitHub Desktop.
Java Template Method (Design Pattern) [French/Français]
Java Template Method (Design Pattern) [French/Français]
public class Main {
public static void main(String... args) {
MTLPizza mtlPizza = new MTLPizza();
mtlPizza.fairePizza();
NYPizza nyPizza = new NYPizza();
nyPizza.fairePizza();
}
}
public class MTLPizza extends PizzaMaker{
@Override
public void ajouterGarniture() {
System.out.println("Garniture Montreal "+getClass().getName());
}
}
public class NYPizza extends PizzaMaker{
@Override
public void ajouterGarniture() {
System.out.println("Garniture New York "+getClass().getName());
}
}
public abstract class PizzaMaker {
public void fairePizza() {
fairePate();
ajouterGarniture();
cuire();
couper();
emballer();
System.out.println("\n\n\n\n");
}
public void fairePate() {
System.out.println("Faire pate "+getClass().getName());
}
public abstract void ajouterGarniture();
public void cuire() {
System.out.println("Cuire "+getClass().getName());
}
public void couper() {
System.out.println("Couper "+getClass().getName());
}
public void emballer() {
System.out.println("Emballer "+getClass().getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment