design_model(9)decorator
1.装饰模式
允许向一个现有的对象添加新的功能,同时又不改变其结构。装饰者可以在所委托被装饰者的行为之前或之后加上自己的行为,以达到特定的目的。
2.实例
public interface Car { public abstract void move(); } class ICar implements Car { protected ICar icar; public void move() { } } class FlyCar implements Car { private Car car; public FlyCar(Car car) { super(); this.car = car; } public void move() { car.move(); System.out.println(); } } public class Client { public static void main(String[] args) { FlyCar flyCar = new FlyCar(new ICar()); flyCar.move(); } }