Interfaces and Loose Coupling in Java by Charlie Calvert
作者: 出处: 更新时间:2007-10-25 责任编辑:
 
 

The Untitled1 class creates instances of three classes which implement the List interface. Figure 2 shows what class Untitled1 looks like in a UML diagram. Figure 3, 4 and 5 show that ArrayList, Vector and LinkedList all implement the List interface. Figure 6 shows a UML view of the List interface.

Figure 2: In this UML dialog a solid line ending in an open arrow shows that Untitled1 contains instances of the ArrayList, LinkedList and Vector classes. Compare with the dotted line and closed arrow symbol shown in Figure 3.

Figure 3. ArrayList implements the List interface.

Figure 4. LinkedList implements the List interface.

Figure 5. Vector implements the List interface.

Figure 6. The List interface as seen in a UML diagram. The plus signs represent public methods. Compare with Figure 2, where JBuilder standard icons from the Structure Pane are displayed. JBuilder allows displaying UML in either mode.

The ArrayList, LinkedList and Vector classes all conform to the contract established by the List interface. Unlike the Runnable interface, the List interface declares multiple methods. By conforming to this contract, the ArrayList, LinkedList and Vector classes all promise to implement the methods of the List interface such as add(), get(), indexOf() and isEmpty(). In other words, these classes all display the behavior associated with the List interface. Is this sense, they all belong to the same family.

Most experienced drivers can pilot any reasonably sized car. They can do this because the interface for a car is the same in most vehicles, whether that car is a Honda, a Ford or a BMW. In the same way, most developers who know the List interface can use the ArrayList, LinkedList and Vector classes. Just as all cars have a steering wheel and a transmission, so do all classes that implement the List interface have methods such as add(), get() and indexOf(). In this sense, all these classes behave in the same manner.

 
     
 
 
后退<<上一页 继续>>下一页
[上一页][第1页][第2页][第3页][第4页][下一页]
 
内容导航  
第1页Interfaces and Loose.. 第2页Interfaces and Loose..
第3页Interfaces and Loose.. 第4页Java
上一篇 : 放弃WinRAR,来到7-Zip的.. 下一篇PPLive联手NOD32新版评测..
 
  您要为所发表的言论的后果负责,请各位遵纪守法并注意文明用语
标题:  

[ 关于本站 ] [ 广告服务 ] [ 商务合作 ] [ 联系我们 ] [ 合作伙伴 ] [ 法律顾问 ] [ 网站地图 ]
千橡公司 京ICP证041489号 Copyright (c) 1997-2007 All Right Reserved.