紧耦合有依赖的写法:
松耦合没依赖的写法:
依赖注入最大的两个好处是:
class Employee {
Address address;
Employee() {
address = new Address();
}
}
class Employee {
Address address;
Employee(Address address) {
this.address=address;
}
}
依赖注入最大的两个好处是:
- 代码松耦合, 易维护
- 易测试