代理:将一个成员对象置于所要构造的类中(就像组合),但与此同时我们在新类中暴漏了该成员对象的所有方法(就像继承);俗称静态代理
    示例如下:

    1. public class SpaceShipControls {
    2. void up(int velocity) {}
    3. void down(int velocity) {}
    4. void left(int velocity) {}
    5. void right(int velocity) {}
    6. void forward(int velocity) {}
    7. void back(int velocity) {}
    8. void turboBoost() {}
    9. }
    10. public class SpaceShipDelegation {
    11. private String name;
    12. SpaceShipDelegation(String name){
    13. this.name =name;
    14. }
    15. //持有该对象得引用 具体干活的对象
    16. private SpaceShipControls shipControls = new SpaceShipControls();
    17. //暴漏SpaceShipControls的方法
    18. public void up(int velocity) {
    19. // 可以加上自己的处理
    20. shipControls.up(velocity);
    21. }
    22. public static void main(String... args){
    23. SpaceShipDelegation protector =new SpaceShipDelegation("NSEA Protector");
    24. protector.up(100);
    25. }
    26. }