Some Coding Considerations - PowerPoint PPT Presentation

About This Presentation
Title:

Some Coding Considerations

Description:

Some Coding Considerations Collection Classes Use the collection classes in the java.util package. The type declaration should refer to the interface, not the ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 8
Provided by: PeterCa84
Category:

less

Transcript and Presenter's Notes

Title: Some Coding Considerations


1
Some Coding Considerations
2
Collection Classes
  • Use the collection classes in the java.util
    package.
  • The type declaration should refer 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 lt n i)
  • doSomething( list.get(i) )

4
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
5
3
4
1
2
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

7
Testing
  • Keep a classs unit test code in either
  • The classs main method
  • Quick simple
  • Not optimized for regression testing
  • Increases classs size, even when not testing.
  • A separate class.
  • Our Resources page links to http//www.junit.org/.
  • The Junit Cookbook.
Write a Comment
User Comments (0)
About PowerShow.com