따라서 결론
package com.heaven.mvc.expert001_01;
public interface Tire {
String getBrand();
}
package com.heaven.mvc.expert001_01;
public class KoreaTire implements Tire{
@Override
public String getBrand() {
return "코리아 타이어";
}
}
package com.heaven.mvc.expert001_01;
public class AmericaTire implements Tire{
@Override
public String getBrand() {
return "미국 타이어";
}
}
package com.heaven.mvc.expert001_01;
public class Car {
Tire tire;
public Car() {
tire = new KoreaTire(); //의존 관계 발생!!
//tire = new AmericaTire();
}
public String getTireBrand() {
return "장착된 타이어: "+tire.getBrand();
}
}
package com.heaven.mvc.expert001_01;
public class Driver {
public static void main(String[] args) {
Car car = new Car();
System.out.println(car.getTireBrand());
}
}