Created
November 9, 2017 14:21
-
-
Save marc-x-andre/c2e12e83f48df27e18beb912010f8502 to your computer and use it in GitHub Desktop.
Java Template Method (Design Pattern) [French/Français]
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
Java Template Method (Design Pattern) [French/Français] |
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
public class Main { | |
public static void main(String... args) { | |
MTLPizza mtlPizza = new MTLPizza(); | |
mtlPizza.fairePizza(); | |
NYPizza nyPizza = new NYPizza(); | |
nyPizza.fairePizza(); | |
} | |
} |
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
public class MTLPizza extends PizzaMaker{ | |
@Override | |
public void ajouterGarniture() { | |
System.out.println("Garniture Montreal "+getClass().getName()); | |
} | |
} |
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
public class NYPizza extends PizzaMaker{ | |
@Override | |
public void ajouterGarniture() { | |
System.out.println("Garniture New York "+getClass().getName()); | |
} | |
} |
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
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