本文介绍了关于java上下文的委托示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是Java授权?任何人都可以给我一个正确的例子吗?
What is delegation in Java? Can anyone give me a proper example?
推荐答案
这是代表团 - 与现实世界完全一样:
That's delegation - exactly like in the real world:
public interface Worker() {
public Result work();
}
public class Secretary() implements Worker {
public Result work() {
Result myResult = new Result();
return myResult;
}
}
public class Boss() implements Worker {
private Secretary secretary;
public Result work() {
return secretary.work();
}
}
(添加了工具界面以更接近Delegator模式)
(Added Worker interface to get closer to the Delegator pattern)
这篇关于关于java上下文的委托示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!