Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
VentureQ committed Jul 12, 2021
1 parent a58cf0c commit 91c8842
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
33 changes: 33 additions & 0 deletions code/Design_Pattern/模板方法模式/HummerH1.java
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();
}
}
33 changes: 33 additions & 0 deletions code/Design_Pattern/模板方法模式/HummerH2.java
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();
}
}
14 changes: 14 additions & 0 deletions code/Design_Pattern/模板方法模式/HummerModel.java
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();
}
}
8 changes: 8 additions & 0 deletions code/Design_Pattern/模板方法模式/Test.java
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();
}
}

0 comments on commit 91c8842

Please sign in to comment.