UML diagram, in order to show the core of the Proxy mode class relationship, here the details of the section, such as Pursui and schoolgirl relationship is not drawn, the core of the proxy mode is the proxy class and the proxy class is implemented by the same interface, you can control access to a class of methods, before the call method to do the pretreatment, To do a post processing after calling a method
Code structure
public class Client {public
static void Main (string[] args) {
schoolgirl Jiaojiao = new Schoolgirl ("Lee charming Jiao");
Proxy Dali = new proxy (Jiaojiao);
Dali.givedolls ();
Dali.giveflowers ();
}
Public interface Igivegift {
void Givedolls ();
void Giveflowers ();
}
public class Proxy implements Igivegift {
private Pursuit GG;
Public Proxy (schoolgirl mm) {
GG = new Pursuit (mm);
}
@Override public
void Givedolls () {
if (GG!= null) {
gg.givedolls ()
}} @Override public
void Giveflowers () {
if (GG!= null) {
gg.giveflowers ()
}}}
public class Pursuit implements Igivegift {
private schoolgirl schoolgirl;
Public Pursuit (schoolgirl schoolgirl) {
super ();
This.schoolgirl = schoolgirl;
}
@Override public
void Givedolls () {
System.out.println (schoolgirl.getname () + ", send you A Doll");
}
@Override public
void Giveflowers () {
System.out.println (schoolgirl.getname () + ", send you Flowers");
}
public class Schoolgirl {
private String name;
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
Public schoolgirl (String name) {
super ();
this.name = name;
}
Run results