and if we invoke that function from many different places, each of which creates their own linkedlist to pass into it, then we cant really claim to be hiding the type of the list from anyone but f. and what good is hiding it from one function when everyone else knows it?
static factory 【程序编程相关:关于Map和List的性能测试报告】fortunately, there are several design patterns that address this issue, and allow us to hide the type of an object even from those who seek to create it. these patterns are known as factories. 【推荐阅读:用BeanShell实现公式管理】
in some sense, the names of the two lists are unfortunate. they might have been better named insertionlist and indexedaccesslist. these two names decouple the reason that the two lists exist from their implementation style. we can enforce that decoupling by creating a class named listfactory that passes the following test: 【扩展信息:设计合适的接口】
consider why we would choose a linkedlist over an arraylist. linkedlists have fast insert times, but slow indexed access times. for example, you can quickly insert or delete an element of a linked list in o(1) time; but it takes o(n) time to find the nth element. the situation for an arraylist is reversed. inserts are o(n), while indexed access is o(1). so the reason to choose one over the other depends on what we plan to do with the list.
... 下一页