-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Design_Pattern.模板方法模式; | ||
|
||
//悍马H1 | ||
public class HummerH1 extends HummerModel { | ||
|
||
@Override | ||
public void start() { | ||
System.out.println("H1发动……"); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.out.println("H1停止……"); | ||
} | ||
|
||
@Override | ||
public void alarm() { | ||
System.out.println("H1鸣笛……"); | ||
} | ||
|
||
@Override | ||
public void engineBoom() { | ||
System.out.println("H1轰鸣……"); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
this.start(); | ||
this.engineBoom(); | ||
this.alarm(); | ||
this.stop(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Design_Pattern.模板方法模式; | ||
|
||
//悍马H2 | ||
public class HummerH2 extends HummerModel { | ||
|
||
@Override | ||
public void start() { | ||
System.out.println("H2发动……"); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.out.println("H2停止……"); | ||
} | ||
|
||
@Override | ||
public void alarm() { | ||
System.out.println("H2鸣笛……"); | ||
} | ||
|
||
@Override | ||
public void engineBoom() { | ||
System.out.println("H2轰鸣……"); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
this.start(); | ||
this.engineBoom(); | ||
this.alarm(); | ||
this.stop(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package Design_Pattern.模板方法模式; | ||
|
||
public abstract class HummerModel { | ||
public abstract void start(); //发动 | ||
public abstract void stop(); //停止 | ||
public abstract void alarm(); //鸣笛 | ||
public abstract void engineBoom(); //轰鸣 | ||
public void run() { //车总归要跑 | ||
this.start(); | ||
this.engineBoom(); | ||
this.alarm(); | ||
this.stop(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Design_Pattern.模板方法模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
HummerH1 h1 = new HummerH1(); | ||
h1.run(); | ||
} | ||
} |