naming conventions

R

Roedy Green

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?
 
A

Alexandr Molochnikov

Most of naming conventions you are asking about have already been
established:
1. taking data and putting it in GUI Components for display.

Setter methods. E.g. setText() in JComponent. If generality is required, I
would use setValue() with the parameter of different primitive data type or
class.
2. sucking data out of GUI components, and validating it.

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
value.
3. converting data from internal form to String

String's valueOf() with parameter of various data types.
4. converting data from String representation to internal form, e.g.
Date, int and validating it.

integerValueOf(), doubleValueOf(), booleanValueOf() etc. See above for the
validation part.
5. serialising and writing an object.

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() ).
6. reading and reconstituting an object.

Object getObject(byte[] data).

Or "instantiate" instead of "getObject".
What sort of method names would you use for those processes for single
fields and for groups of fields or entire objects?

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",
"").
 
P

P.Hill

Alexandr said:
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.

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.

-Paul
 
R

Roedy Green

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.

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

Christophe Vanfleteren

Roedy said:
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.

Isn't binding the standard term for "setting the GUI components to data
values"?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top