static void Main(string[] args) { //没有加入依赖对象声明,修改Tire类的属性会导致全部类进行修改 Car car = new Car(); car.Run(); //依赖对象声明调用 Tire tire = new Tire(10); Bottom bottom = new Bottom(tire); Framework framework = new Framework(bottom); Car newCar = new Car(framework); newCar.Run(); }
/// <summary> /// Dependency Injection /// </summary> /// <param name="tire"></param> public Bottom(Tire tire) { this.tire = tire; }
public Bottom() { this.tire = new Tire(); }