介绍
- 高层模块不应该依赖底层模块,二者都应该依赖其抽象(抽象类,接口)。
- 抽象不应该依赖细节(具体实现类),细节应该依赖抽象
- 核心思想:面向接口编程
- 相对于细节的多变性,抽象的稳定性,以抽象为基础的构架,比以接口为基础的构架要稳定的多。
- 是用抽象是为具体的规范,而不涉及任何具体操作,把展示细节的任务交给实现类。
传递关系有哪些
public class segeration implements IOpenAndColse {
public void open(ITv tv){
tv.play();
}
}
interface IOpenAndColse{
void operation1();
}
interface ITv{
void play();
}
public class segeration implements IOpenAndColse {
private ITv tv;
public segeration(ITv tv){
this.tv = tv
}
public open(){
this.tv.play();
}
}
interface IOpenAndColse{
void operation1();
}
interface ITv{
void play();
}
public class segeration implements IOpenAndColse {
private ITV tv;
public void setTV(ITV tv){
this.tv = tv
}
public open(){
this.tv.play();
}
}
interface IOpenAndColse{
void operation1();
}
interface ITV{
void play();
}