naming conventions

Discussion in 'Java' started by Roedy Green, Jun 29, 2004.

  1. Roedy Green

    Roedy Green Guest

    Here are some vocabulary / method naming questions.

    What verbs would you use to describe the following:

    1. taking data and putting it in GUI Components for display.

    2. sucking data out of GUI components, and validating it.

    3. converting data from internal form to String

    4. converting data from String representation to internal form, e.g.
    Date, int and validating it.

    5. serialising and writing an object.

    6. reading and reconstituting an object.

    What sort of method names would you use for those processes for single
    fields and for groups of fields or entire objects?
    Roedy Green, Jun 29, 2004
    1. Advertisements

  2. Most of naming conventions you are asking about have already been
    Setter methods. E.g. setText() in JComponent. If generality is required, I
    would use setValue() with the parameter of different primitive data type or
    Getter methods. For JComponent this would be getText(). Again, for
    generality reasons, one can use getValue() that returns an Object, like Date
    or Boolean, or getInteger(), getDouble() etc. for primitives.

    For validation, I usually use boolean isValid(), or int validate() if the
    validation process must return more than just a black-and-white true/false
    String's valueOf() with parameter of various data types.
    integerValueOf(), doubleValueOf(), booleanValueOf() etc. See above for the
    validation part.
    public byte[] convertObjectToBytes(Object obj)

    (this is the method I actually use in one of the database adaptors, a more
    consistent name would have been getByteArray() ).
    Object getObject(byte[] data).

    Or "instantiate" instead of "getObject".
    When I have a group of polymorphically compatible objects, I usually put
    them in a Collection of my own making (subclass of Vector) that implements
    "makeObjectsPerform" method with a String for the method name and parameter
    to pass to the method, and have it walk through the entire Collection,
    sending each element the same message with the same parameter (using the
    reflection mechanism). Something like list.makeObjectsPerform("setText",
    Alexandr Molochnikov, Jun 29, 2004
    1. Advertisements

  3. Roedy Green

    P.Hill Guest

    I think Roedy may have been asking about name of the controller method which
    calls the getters and does the validation, not the name of the getter.

    P.Hill, Jun 30, 2004
  4. Roedy Green

    Roedy Green Guest

    I was thinking more of both. The basic method is typically getText on
    the Component itself, but here is usually some additional massaging
    that has to happen at the field level to turn that text into something
    clean for computation.

    We still don't have unambiguous verbs for "setting the GUI components
    to data values" and "fetching internal values from GUI components".

    I think it might be fun to coin some.

    Perhaps peek and poke could be recycled.

    grab and stuff?

    glean and display?

    If such words came into common use, it would make code easier to read,
    especially if the verbs had definite implications about what could NOT
    be done in those methods.
    Roedy Green, Jun 30, 2004
  5. Isn't binding the standard term for "setting the GUI components to data
    Christophe Vanfleteren, Jun 30, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.