diff --git a/src/main/java/com/msb/proxy/v5/Movable.java b/src/main/java/com/msb/proxy/v5/Movable.java new file mode 100644 index 0000000..1b076fd --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/Movable.java @@ -0,0 +1,11 @@ +package com.msb.proxy.v5; + +/** + * @Author bingor + * @Date 2022/10/17 9:40 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ +public interface Movable { + public void move(); +} diff --git a/src/main/java/com/msb/proxy/v5/ProxyTank.java b/src/main/java/com/msb/proxy/v5/ProxyTank.java new file mode 100644 index 0000000..bf7e807 --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/ProxyTank.java @@ -0,0 +1,30 @@ +package com.msb.proxy.v5;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class ProxyTank implements Movable { + + private Tank tank = new Tank(); + + @Override + public void move() { + long startTime = System.currentTimeMillis(); + tank.move(); + long entTime = System.currentTimeMillis(); + System.out.println(entTime - startTime); + } + + public static void main(String[] args) { + new ProxyTank().move(); + } +} diff --git a/src/main/java/com/msb/proxy/v5/Tank.java b/src/main/java/com/msb/proxy/v5/Tank.java new file mode 100644 index 0000000..942dc06 --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/Tank.java @@ -0,0 +1,27 @@ +package com.msb.proxy.v5;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank implements Movable { + @Override + public void move() { + System.out.println("tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/msb/proxy/v6/Main.java b/src/main/java/com/msb/proxy/v6/Main.java new file mode 100644 index 0000000..e7d664a --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Main.java @@ -0,0 +1,19 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:59 + * @Description: com.msb.proxy.v6 + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:59 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + new TankLogProxy(new TankTimeProxy(new Tank())).move(); + } +} diff --git a/src/main/java/com/msb/proxy/v6/Movable.java b/src/main/java/com/msb/proxy/v6/Movable.java new file mode 100644 index 0000000..0796ea1 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Movable.java @@ -0,0 +1,11 @@ +package com.msb.proxy.v6; + +/** + * @Author bingor + * @Date 2022/10/17 9:40 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ +public interface Movable { + public void move(); +} diff --git a/src/main/java/com/msb/proxy/v6/Tank.java b/src/main/java/com/msb/proxy/v6/Tank.java new file mode 100644 index 0000000..055f797 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Tank.java @@ -0,0 +1,27 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank implements Movable { + @Override + public void move() { + System.out.println("tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/msb/proxy/v6/TankLogProxy.java b/src/main/java/com/msb/proxy/v6/TankLogProxy.java new file mode 100644 index 0000000..20bbc90 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/TankLogProxy.java @@ -0,0 +1,30 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class TankLogProxy implements Movable { + + private Movable movable; + + public TankLogProxy(Movable movable) { + this.movable = movable; + } + + @Override + public void move() { + System.out.println("move start run"); + movable.move(); + System.out.println("move end run"); + } + +} diff --git a/src/main/java/com/msb/proxy/v6/TankTimeProxy.java b/src/main/java/com/msb/proxy/v6/TankTimeProxy.java new file mode 100644 index 0000000..28106ea --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/TankTimeProxy.java @@ -0,0 +1,31 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class TankTimeProxy implements Movable { + + private Movable movable; + + public TankTimeProxy(Movable movable) { + this.movable = movable; + } + + @Override + public void move() { + long startTime = System.currentTimeMillis(); + movable.move(); + long entTime = System.currentTimeMillis(); + System.out.println(entTime - startTime); + } + +}