60 likes | 76 Views
Some Coding Considerations. Collection Classes. Use collection classes in the java.util package. The type declaration refers to the interface , not the implementation. Yes: import java.util.List; . . . List views = new ArrayList(); No: ArrayList views = new ArrayList();.
E N D
Collection Classes • Use collection classes in the java.util package. • The type declaration refers to the interface, not the implementation. Yes: import java.util.List; . . . List views = new ArrayList(); No: ArrayList views = new ArrayList();
Collection Iteration Idioms • For standard collection instance, c: for (Iterator i = c.iterator(); i.hasNext; ) { doSomething( i.next() ); } • For high-performance iteration over random access list, list: for ( int i = 0, n = list.size(); i < n; i++) { doSomething( list.get(i) ); }
7 6 3 5 4 2 1 Implementation Order • For acyclic classes, implement/test classes bottom-up. • The figure is an example. • Arcs represent uses relation • Node numbers indicate an ordering.
Implementation Order … For cyclic classes, test nodes referring to each other at the same time. or • Test aspects of 4 that do not refer to 5 • Test aspects of 5 that do not refer to 4. • Test aspects of 4 that refer to 5. • Test aspects of 5 that refer to 4. 7 6 3 5 4 2 1
Test-First • The general class development algorithm is approximately as follows: while ( ! class.isComplete ) { write a little test code; write the corresponding production code; }