JDK中的Logger、SL4J就是典型的实践者,另外WEB的层级结构就是最好的诠释。
public interface ISpareribs {
public void juice();
public void fry();
public void preserve();
public void prepare();
}
做一顿饭需要很多步骤
public class Spareribs implements ISpareribs {
@Override
public void fry() {
System.out.println("翻炒许。。。然后。。。。。。。。。。。。。。。");
}
@Override
public void juice() {
System.out.println("最后浇汁。。。倥焖。。。。。。。。。。。。。。。");
}
@Override
public void prepare() {
System.out.println("准备少许。。。一克。。。。。。。。。。。。。。。");
}
@Override
public void preserve() {
System.out.println("将排骨。。。生姜。。。。。。。。。。。。。。。");
}
}
/**
* 向外界公布的接口,就是做糖醋排骨,细节就不要管了
* @author xsy
*
*/
public interface ICookFacade {
public void cookSpareribs();
}
public class CookFacade implements ICookFacade {
private final ISpareribs spareribs = new Spareribs();
@Override
public void cookSpareribs() {
spareribs.prepare();
spareribs.preserve();
spareribs.fry();
spareribs.juice();
}
}
测试
public class Client {
public static void main(String[] args) {
//我客户端只管吃,不管怎么做的
// ISpareribs spareribs = new Spareribs();
// spareribs.prepare();
// spareribs.preserve();
// spareribs.fry();
// spareribs.juice();
ICookFacade cookFacade = new CookFacade();
cookFacade.cookSpareribs();
}
}