1. package com.snails.chapter7.three;
    2. /**
    3. * @author Snails
    4. * @date 2021/5/7 22:01
    5. */
    6. public class SpaceShip extends SpaceShipControls {
    7. private String name;
    8. public SpaceShip(String name){
    9. this.name = name;
    10. }
    11. @Override
    12. public String toString() {
    13. return name;
    14. }
    15. }
    1. package com.snails.chapter7.three;
    2. /**
    3. * @author Snails
    4. * @date 2021/5/7 22:00
    5. */
    6. public class SpaceShipControls {
    7. void up(int velocity){}
    8. }
    1. package com.snails.chapter7.three;
    2. /**
    3. * @author Snails
    4. * @date 2021/5/7 21:59
    5. */
    6. public class SpaceShipDelegation {
    7. private String name;
    8. private SpaceShipControls controls = new SpaceShipControls();
    9. public SpaceShipDelegation(String name){
    10. this.name = name;
    11. }
    12. public void up(int velocity){
    13. controls.up(velocity);
    14. }
    15. public static void main(String[] args) {
    16. SpaceShipDelegation nsea = new SpaceShipDelegation("NSEA");
    17. nsea.up(100);
    18. }
    19. }