联系方式

咨询热线:400-998-6158

点击此处免费预约试听课程»

常见问题
学习资讯
师资介绍
学习资讯

装饰设计模式与静态代理设计模式的区别是什么

这是一个装饰设计模式的代码:
public class DecoratorTest01 {
public static void main(String[] args) {
new Amplifier(new Person(10)).say();
}
}
interface Say{
void say();
}
class Person implements Say{
int voice;
public Person(int voice) {
this.voice = voice;
}
public void say() {
System.out.println("人的声音为:" + voice);
}
}
class Amplifier implements Say{
Person p;
public Amplifier(Person p) {
this.p = p;
}
public void say() {
System.out.println("人的声音为:" + p.voice * 10);
}
}

这是多线程静态代理设计模式的代码:
public class Test01{
public static void main(String[] args) {
new Thread(new Test()).start();
}
}
class Test implements Runnable{
public void run() {
System.out.println("多线程静态代理设计模式");
}
}
这是jdk1.8中多线程静态代理部分源码:
public interface Runnable {
public abstract void run();
}
public class Thread implements Runnable {
private Runnable target;
public Thread(Runnable target) {
init(null, target, "Thread-" + nextThreadNum(), 0);
}
public void run() {
if (target != null) {
target.run();
}
}
}

他们的类的实现,以及方法的调用几乎是一样的

学校联系方式

更多培训课程,学习资讯,课程优惠等学校信息,请进入 北京IT培训北京ITIL认证培训北京Oracle数据库认证培训北京华为认证培训 网站详细了解,免费咨询电话:400-998-6158

相关课程