/**
* 本程序主要用来练习静态代理的模式
* 也可为接口的练习题
* @author lzd
*
*/
public class Staticproxy {
public static void main(String[] args) {
Person man = new Staticproxy().new Person("lzd");
man.marry();
Agencycompany agencycompany = new Staticproxy().new Agencycompany(man);
agencycompany.marry();
}
/**
* 结婚接口,
* @author lzd
*
*/
interface Marry
{
void marry();
}
/**
* 结婚主
* @author lzd
*
*/
class Person implements Marry
{
private String name;
public Person(String name) {
this.name = name;
}
public String toString()
{
return name;
}
@Override
public void marry() {
System.out.println("I will get married with a woman");
}
}
/**
* 婚庆公司
* @author lzd
*
*/
class Agencycompany implements Marry
{
Person man;
public Agencycompany(Person man) {
this.man = man;
}
public void before() {
System.out.println("make compare for them");
}
public void after() {
System.out.println("get money from them");
}
@Override
public void marry() {
before();
System.out.println("Running in marry for "+man.toString());
after();
}
}
}