第一步:创建接口
public interface IPost {
void post(String body);
}
第二步:实现接口
public class IPostImpl implements IPost {
@Override
public void post(String body) {
System.out.println(body);
}
}
第三步:创建代理类
public class PostProxy implements IPost {
IPost post;
public PostProxy(IPost post) {
this.post = post;
}
@Override
public void post(String body) {
System.out.println("show loading");
post.post(body);
System.out.println("dismiss loading");
}
}
第四步:使用
public class Main {
public static void main(String[] args) {
IPostImpl postImpl = new IPostImpl();
PostProxy post = new PostProxy(postImpl);
post.post("request params");
}
}
网友评论