package staticProxy;
public class Girl {
private String name;
public Girl(){}
public Girl(String name)
{
this.name = name;
}
public String toString()
{
return name;
}
}
package staticProxy;
public class XiaoFang extends Girl{
public XiaoFang()
{
super("xiao fang");
}
}
package staticProxy;
public class Man {
private String name;
public Man(String name)
{
this.name = name;
}
public String first(Girl girl)
{
return name+" send "+girl+" flowers";
}
public String secondly(Girl girl)
{
return name+" eating with "+girl;
}
public String third(Girl girl)
{
return name+" with "+girl+" engagement";
}
}
package staticProxy;
public class XiaoQiang extends Man{
public XiaoQiang()
{
super("xiao qiang");
}
}
package staticProxy;
public class DaQiang extends Man
{
public DaQiang()
{
super("da qiang");
}
}
package staticProxy;
public class Main
{
public static void main(String[] args)
{
XiaoFang xiaoFang = new XiaoFang();
Man xiaoQiang = new XiaoQiang();
Man daQiang = new DaQiang();
MatchmakingService ms = new MatchmakingService(daQiang,xiaoFang);
ms.todo();
MatchmakingService mss = new MatchmakingService(xiaoQiang,xiaoFang);
mss.todo();
}
}
/**
* 静态代理模式只能静态的做某些事,总感觉这个不对,等深入了解后,好好写个
* 静态代理将两个对象完全隔开,由一个代理类去做被代理的事情,所有的被代理的都可以通过代理类
* 做相同的事,也可以设定一定的条件,而代理的就不知道被代理的是谁,只只知道代理类,代理类
* 相当于相亲中的媒婆。
*/
分享到:
评论