当前位置:网站首页>Static proxy mode
Static proxy mode
2022-06-26 05:59:00 【Mr.Rop】
// Static proxy pattern
/* * Real objects and proxy objects should implement the same interface * The proxy object is to represent the real role * */
// benefits :
// Proxy objects can do a lot of things that real objects can't
// Real objects focus on doing their own things
public class StaticProxy {
public static void main(String[] args) {
You you = new You();
you.HappyMarry();
System.out.println("===================");
WeddingCompany weddingCompany = new WeddingCompany(new You());
weddingCompany.HappyMarry();
}
}
interface Marry{
void HappyMarry();
}
class You implements Marry{
// Real role
@Override
public void HappyMarry() {
System.out.println("HappyMarry");
}
}
class WeddingCompany implements Marry{
// delegable role
private Marry target;
public WeddingCompany(Marry target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
this.target.HappyMarry();
after();
}
private void before() {
System.out.println(" The invitation , Site layout ");
}
private void after() {
System.out.println(" end , Closing payment ");
}
}
边栏推荐
猜你喜欢

状态模式,身随心变

How to use the tablet as the second extended screen of the PC

How Navicat reuses the current connection information to another computer

Ribbon load balancing service call

组合模式、透明方式和安全方式

Redis底层数据结构

E-commerce seeks growth breakthrough with the help of small program technology

家庭记账程序(第二版 加入了循环)

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

怎么把平板作为电脑的第二扩展屏幕
随机推荐
Written before father's Day
Some doubts about ARP deception experiment
Status mode, body can change at will
Upgrading technology to art
【群内问题学期汇总】初学者的部分参考问题
Spark source code analysis (I): RDD collection data - partition data allocation
Machine learning 05: nonlinear support vector machines
The use of loops in SQL syntax
FindControl的源代码
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
跨域的五种解决方案
转帖——不要迷失在技术的海洋中
Thinking about bad money expelling good money
Machine learning 07: Interpretation of PCA and its sklearn source code
Day3 - variables and operators
How to use the tablet as the second extended screen of the PC
C generic speed
Easy to understand from the IDE, and then talk about the applet IDE
05. basic data type - Dict
numpy.log