本文主要是介绍java中 静态代理模式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
编写代码
package com.xiang.lesson07;
public class StacticProxy {
public static void main(String[] args) {
Wedding wedding = new Wedding();
wedding.Wedding(new You());
wedding.HappyMarry();
}
}
interface Marry {
void HappyMarry();
}
//真实角色
class You implements Marry {
@Override
public void HappyMarry() {
System.out.println("marry...........");
}
}
//代理角色
class Wedding implements Marry {
private Marry target;
public Wedding(){
}
public void Wedding(Marry target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
this.target.HappyMarry();
after();
}
private void before() {
System.out.println("before...........");
}
private void after() {
System.out.println("after..............");
}
}
运行结果
这篇关于java中 静态代理模式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!