依赖倒置原则

package com.huawei.entity;
/**
* 如果一个类与其他一个类耦合性非常高,我了降低耦合性
* 将其他的类设为接口,其他类都实现接口,
* 这样这个类和其他类的耦合性降低
* @author Administrator
*
*/
public class Dependence {

public static void main(String[] args) {
Mother mother=new Mother();
IReader iReader=new Book();
mother.gushi(iReader);
}

}

interface IReader{
void read();
}
class Mother{
public void gushi(IReader iReader){
System.out.println("妈妈");
iReader.read();
}
}
class Book implements IReader{

public void read() {
System.out.println("老人与海");
}

}

原文地址:https://www.cnblogs.com/javaweb2/p/6243886.html