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