1 / 6

Some Coding Considerations

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();.

janbowen
Download Presentation

Some Coding Considerations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Some Coding Considerations

  2. 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();

  3. 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) ); }

  4. 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.

  5. 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

  6. Test-First • The general class development algorithm is approximately as follows: while ( ! class.isComplete ) { write a little test code; write the corresponding production code; }

More Related