Chapter 4 . Names


Chapter 4. Names

Exercise 9. Names
  • addItem(item) ” embedded type

  • doIt() ” may be OK, may be uncommunicative , depending on context

  • getNodesArrayList() ” embedded type

  • getData() ” uncommunicative (perhaps)

  • makeIt() ” uncommunicative (perhaps)

  • multiplyIntInt() ” embedded type

  • processItem() ” embedded type or uncommunicative

  • sort () ” OK

  • spin() ” OK (depending on the domain)


Exercise 10. Critique the Names

If there's an area of personal taste, it's probably in names. Don't be surprised if your answers differ .

A. Clear() or erase() both sound OK (depending on whatever the library or other code uses). DeleteAll() seems clunky . Wash() might be OK for a pane-of-glass simulation, but it seems strained for this purpose.

B. Push() is traditional; add() is probably OK if that's what everything else in the collection library is using. Insert() seems misleading, since stacks don't put items in the middle. AddToFront() is odd as well; we think of queues having fronts but of stacks as having tops.

C. Cut() implies that the text is saved somewhere for pasting. delete() is probably best; clear() and erase() may be OK, but to my ears they sound like they might apply to the whole document.

D. Equals() is the out-of-the-box Java word. IdenticalTo() might work if equals() is inappropriate for some reason. Matches() could work, but carries a little baggage suggesting it might be a pattern match. Compare() is the worst of the lot; the other terms let us know "returns true if they're equal"; compare() doesn't tell us which way the answer will come out.

Exercise 11. XmlEditor

A. My choice for the parent class would be Editor.

B. The interface can be called Editor, and the parent of XmlEditor can be called AbstractEditor. (I'd be content to let it evolve ; it might happen that the only classes would be an interface Editor and an implementation XmlEditor.)




Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net