Over the past few days, I 've learned Kent Beck's implementation patterns, probably because I just finished reading design patterns and thought the author's language was too casual, design patterns is more logical.
The so-called implementation mode also lacks some programming skills. From the perspective of the design mode, it is just a trick.
In addition, the book is far-fetched in many places. Maybe because I am not a Java programmer, a lot of content in the book cannot be understood, but I still insist on reading it.
Read the collections chapter carefully and take the following notes.
1 collections hover in a strange world halfway between a programming language construct and a library.
In fact, we can see from the Development of C to C ++ that collection in C can be obtained only through construct, and STL in C ++ has become the first-class language element.
2 metaphors.
- The first is that of a multi-valued variable.
- The second metaphor mixed into collections is that of objects --- a collection is an object.
- A third metaphor useful for thinking about collections is that of mathematical sets.
3 issues
- The first concept expressed by collections is their size.
- A second concept expressed through collections is whether or not the order of elements is important.
- Another issue to be expressed by collections is the uniqueness of elements.
4 Interfaces
Android seems to have a sparsearray, which is equivalent to the difference in Map <integer, Object> and performance.
- Array
- Iterable
- Collection
- List
- Set
- Sortedset
- Map
5 implementations
As with all performance issues, it is best to pick a simple implementation to begin with and then tune based on experience. if you see a profile dominated by callto add () or remove (), consider switching an arraylist
A shortlist.
6 collections
- Searching
- Call collections. binarysearch (list, element) to return the index of an element in the list
- Sorting
- Shuffle (list), reverse (list), sort (list), sort (list, comparator)
- Unlike binary search, sorting performance is roughly the same for arraylist and tables list, because the elements are first copied into an array, the array is sorted, and then the elements are copied back.
- Unmodifiable collections
- Collections. unmodifiablecollection ()
- Single-element collections
- Collections. Singleton ()
7 extending collections
Adapter
The collection function in Java is quite powerful, and different collections can be used in different occasions.
This is also a problem that I didn't realize in the android code. Basically, arraylist is used, although the data volume is small.
Therefore, to improve the performance, we still need to have a deep language skills. In Java, it is what I lack.