关于java上下文的委托示例 [英] delegation example regarding java context

查看:100
本文介绍了关于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上下文的委托示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆