1.创建一个要被代理的类
package thinkinjava.reusing; public class SpaceShipControls { void up(int velocity){} void down(int velocity){} void left(int velocity){} void right(int velocity){} void forward(int velocity){} void back(int velocity){} void turboBoost(){} }
2.在类SpaceShipDelegation创建一个代理类的变量
package thinkinjava.reusing; public class SpaceShipDelegation { private String name; private SpaceShipControls controls = new SpaceShipControls(); }
3.在SpaceShipDelegation类内,在声明变量controls分号的后面,右键鼠标选择Generate,选择:Delegate Methods