UI Swing turorial online.
Related page:
 http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html
source code:
 http://java.sun.com/docs/books/tutorial/uiswing/layout/examples/SpringDemo2.javaMy question is about this line:
      SpringLayout layout = new SpringLayout();As we know, class SpringLayout is implemented the interface LayoutManger, so this SpringLayout-to-LayoutManager is is-a relation. But when I replace it by:
      LayoutManager layout = new SpringLayout();
Problem occurs, the IDE indicates that methods cannot be found.Jeff Yan说过依赖于抽象的依赖反转原则DIP,这里怎么没有效果呢?我错哪里了?

解决方案 »

  1.   

    to shoyonder(笑天) 
    迪米特法则(law of Detemetr)说的是一个对象对其他对象的了解度应该是最少。而DIP说的依赖于抽象(比如接口)进行编程。比如ArrayList的建立:
                  List al = new ArrayList();而不是ArrayList al = new ArrayList();
      

  2.   

    此问题在www.javaworld.com.tw上已经有了完整的回复。
    http://www.javaworld.com.tw/jute/post/view?bid=29&id=167399&tpg=1&ppg=1&sty=1#167498