我的隐式生活(My Implicit Life)

继续搞“对象”,玩OO.

首页 新随笔 联系 聚合 管理
  11 Posts :: 1 Stories :: 39 Comments :: 0 Trackbacks

The interfaces that are concerned with holding objects are Collection, List, Set, and Map.Ideally, you’ll write most of your code to talk to these interfaces, and the only place where you’ll specify the precise type you’re using is at the point of creation. So you can create a List like this:

List x = new LinkedList();


Of course, you can also decide to make x a LinkedList (instead of a generic List)and carry the precise type information around with x. The beauty (and the intent) of using the interface is that if you decide you want to change your implementation, all you need to do is change it at the point of creation, like this:

List x = new ArrayList();


The rest of your code can remain untouched (some of this genericity can also be achieved with iterators).

操。以前怎么就没人这么讲过呢。妈的,都是垃圾!

posted on 2006-09-01 17:16 marco 阅读(220) 评论(0)  编辑  收藏 所属分类: -=Design Pattern=-

只有注册用户登录后才能发表评论。


网站导航: