装饰器和代理模式

代理模式:
public interface Animal {
void run();
}
package com.mrchen.mythirdspring.proxytest;
public class Dog implements Animal{
@Override
public void run() {
System.out.println("dog run");
}
}
package com.mrchen.mythirdspring.proxytest;
public class DogProxy implements Animal{
Animal animal;

public DogProxy(Animal animal) {
this.animal = animal;
}

@Override
public void run() {
animal.run();
System.out.println("run happy");
}
public void jump(){
System.out.println("dog jump");
}
}
package com.mrchen.mythirdspring.proxytest;
public class TestProxy {
public static void main(String[] args){
Dog dog=new Dog();
DogProxy dogProxy=new DogProxy(dog);
dogProxy.run();
}
}

posted @ 2020-12-10 19:17  why414  阅读(62)  评论(0)    收藏  举报