Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Dependency Injection
 /// </summary>
 /// <param name="tire"></param>
 public Bottom(Tire tire)
 {
     this.tire = tire;
 }
Ejemplo n.º 3
0
 public Bottom()
 {
     this.tire = new Tire();
 }