Inconsistent Names


Inconsistent Names

Symptoms

  • One name is used in one place, and a different name is used for the same thing somewhere else. For example, you might see add() , store() , put() , and place() for the same basic feature.

Causes

Different people may create the classes at different times. (People may forget to explore the existing classes before adding more.) Occasionally, you'll find people doing this intentionally (but misguidedly) so they can distinguish the names.

What to Do

Pick the best name, and use Rename Method (or field, constant, etc.) to give the same name to the same things. Once you've done this, you may find that some classes appear to be more similar than they did before. Look for a duplication smell and eliminate it.

Payoff

Improve communication. May expose duplication.

Notes

The Eiffel language uses a common pool of words for the names of its library features. You can use this technique as inspiration: Look to existing library names for the vocabulary you use.

Exercise 10 Critique the Names.

Which name would you expect to use?

  1. To empty a window (onscreen)

    clear()

    wash()

    erase()

    deleteAll()

  2. For a stack

    add()

    insert()

    push()

    addToFront()

  3. For an editor (to get rid of the selected text)

    cut()

    delete()

    clear()

    erase()

  4. As part of a file comparison program

    line1.compare(line2)

    line1.equals(line2)

    line1.identicalTo(line2)

    line1.matches(line2)

See Appendix A for solutions.

Exercise 11 XmlEditor.

You have a class XmlEditor. You want to introduce a parent class.

  1. What do you call it?

  2. You want to introduce an interface that the parent will implement. What's a good name?

See Appendix A for solutions.




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