直接上代码
package com.example.demo.proxy;
/**
* @projectName: demo
* @package: com.example.demo.proxy
* @className: StaticProxy
* @author:
* @description: 结婚代理
* @date: 2021/11/26 16:01
*/
public class StaticProxy {
public static void main(String[] args) {
Person person = new Person();
Company company = new Company(person);
company.HappyMarry();
}
}
//结婚
interface Marry {
void HappyMarry();
}
// 真实角色结婚
class Person implements Marry {
@Override
public void HappyMarry() {
System.out.println("我要去结婚!");
}
}
// 婚庆公司
class Company implements Marry {
private Marry target;
public Company(Marry target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
this.target.HappyMarry();
after();
}
private void before() {
System.out.println("结婚前帮忙婚礼现场!");
}
private void after() {
System.out.println("结婚之后拿钱!");
}
}