added lab6 ex1
This commit is contained in:
parent
061a475a6b
commit
6acdcaffa7
32
src/lab6_template_method/ex1/HellsKitchen.java
Normal file
32
src/lab6_template_method/ex1/HellsKitchen.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
32
src/lab6_template_method/ex1/MacDonalds.java
Normal file
32
src/lab6_template_method/ex1/MacDonalds.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
11
src/lab6_template_method/ex1/Main.java
Normal file
11
src/lab6_template_method/ex1/Main.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
36
src/lab6_template_method/ex1/Restaurant.java
Normal file
36
src/lab6_template_method/ex1/Restaurant.java
Normal file
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user