标签:RKE new oss 示例 sys class pre sse int
一:概念
一个对象接收到了请求,但是自己不处理,交给另外的对象处理,就是委托模式,例如 老板接到了活,
然后把活转手给了工人去做。
二:示例
创建一个类IReceiveTask,代表接收任务的动作
public interface IReceiveTask { void receive(String task); }
创建一个类BossService,老板可以接收任务,并且可以命令工人
public class BossService implements IReceiveTask{ private WorkerService workerService; public BossService(WorkerService workerService){ this.workerService = workerService; } @Override public void receive(String task) { workerService.receive(task); } }
创建一个工人类Worker,工人可以接收任务
public class WorkerService implements IReceiveTask{ @Override public void receive(String task) { System.out.println("工人开始"+task); } }
测试类:
public class TestEntrust { public static void main(String[] args) { String task = "搬砖"; WorkerService workerService = new WorkerService(); BossService bossService = new BossService(workerService); bossService.receive(task); } }
老板接到任务后,把任务委托给了工人做
标签:RKE new oss 示例 sys class pre sse int
原文地址:https://www.cnblogs.com/warrior4236/p/12584215.html