Template method can not be overridden
https://www.oodesign.com/template-method-pattern.html 网址里是这么说的,你怎么看?
This commit is contained in:
parent
a8c5a57065
commit
59129c4fc7
@ -26,9 +26,9 @@ public abstract class CaffeineBeverage {
|
||||
addCondiments();
|
||||
}
|
||||
|
||||
abstract void brew();
|
||||
public abstract void brew();
|
||||
|
||||
abstract void addCondiments();
|
||||
public abstract void addCondiments();
|
||||
|
||||
void boilWater() {
|
||||
System.out.println("boilWater");
|
||||
@ -42,12 +42,12 @@ public abstract class CaffeineBeverage {
|
||||
|
||||
```java
|
||||
public class Coffee extends CaffeineBeverage {
|
||||
@Override
|
||||
|
||||
void brew() {
|
||||
System.out.println("Coffee.brew");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
void addCondiments() {
|
||||
System.out.println("Coffee.addCondiments");
|
||||
}
|
||||
@ -56,12 +56,12 @@ public class Coffee extends CaffeineBeverage {
|
||||
|
||||
```java
|
||||
public class Tea extends CaffeineBeverage {
|
||||
@Override
|
||||
|
||||
void brew() {
|
||||
System.out.println("Tea.brew");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
void addCondiments() {
|
||||
System.out.println("Tea.addCondiments");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user