diff --git a/src/lab6_template_method/ex1/HellsKitchen.java b/src/lab6_template_method/ex1/HellsKitchen.java new file mode 100644 index 0000000..3de579c --- /dev/null +++ b/src/lab6_template_method/ex1/HellsKitchen.java @@ -0,0 +1,32 @@ +package lab6_template_method.ex1; + +public class HellsKitchen extends Restaurant { + public HellsKitchen(String name) { + super("HK " + name); + } + + @Override + public void prepareVegetables() { + log("Preparing nice salad"); + } + + @Override + public void prepareMainMenu() { + log("Creating flavorful dish"); + } + + @Override + public void prepareCheese() { + log("Preparing finest cheese"); + } + + @Override + public void prepareDessert() { + log("Giving birth to awesome dessert"); + } + + @Override + public void prepareCoffee() { + log("Brewing the best coffee"); + } +} diff --git a/src/lab6_template_method/ex1/MacDonalds.java b/src/lab6_template_method/ex1/MacDonalds.java new file mode 100644 index 0000000..26fa200 --- /dev/null +++ b/src/lab6_template_method/ex1/MacDonalds.java @@ -0,0 +1,32 @@ +package lab6_template_method.ex1; + +public class MacDonalds extends Restaurant { + public MacDonalds(String name) { + super("McDonalds " + name); + } + + @Override + public void prepareVegetables() { + log("Vegetables ? What's that ?"); + } + + @Override + public void prepareMainMenu() { + log("McChicken incoming"); + } + + @Override + public void prepareCheese() { + log("Hmmm, creamy cheese"); + } + + @Override + public void prepareDessert() { + log("Preparing McFlurry"); + } + + @Override + public void prepareCoffee() { + log("Preparing short and hot coffee"); + } +} diff --git a/src/lab6_template_method/ex1/Main.java b/src/lab6_template_method/ex1/Main.java new file mode 100644 index 0000000..bc131d1 --- /dev/null +++ b/src/lab6_template_method/ex1/Main.java @@ -0,0 +1,11 @@ +package lab6_template_method.ex1; + +public class Main { + public static void main(String[] args) { + Restaurant r1 = new MacDonalds("Sion"); + Restaurant r2 = new HellsKitchen("London"); + + r1.prepareDinner(); + r2.prepareDinner(); + } +} diff --git a/src/lab6_template_method/ex1/Restaurant.java b/src/lab6_template_method/ex1/Restaurant.java new file mode 100644 index 0000000..3021246 --- /dev/null +++ b/src/lab6_template_method/ex1/Restaurant.java @@ -0,0 +1,36 @@ +package lab6_template_method.ex1; + +public abstract class Restaurant { + private String name; + public Restaurant(String name) { + this.name = name; + } + + public final void prepareDinner() { + serveWater(); + prepareVegetables(); + prepareMainMenu(); + prepareCheese(); + prepareDessert(); + prepareCoffee(); + cleanTable(); + } + + protected void log(String msg) { + System.out.println("[" + name + "] " + msg); + } + + protected final void serveWater() { + log("Serving water"); + } + + protected final void cleanTable() { + log("Cleaning table"); + } + + protected abstract void prepareVegetables(); + protected abstract void prepareMainMenu(); + protected abstract void prepareCheese(); + protected abstract void prepareDessert(); + protected abstract void prepareCoffee(); +}