Page 801 - Introduction to Programming with Java: A Problem Solving Approach
P. 801

                }
<instance-variable-declarations>
//*********************************************************
<trivial-constructor-definition>
<trivial-constructor-definition>
//*********************************************************
<mutator-definition>
Apago PDF Enhancer
<mutator-definition>
<accessor-definition>
<accessor-definition> //********************************************************* <simple-method-definition> //********************************************************* <simple-method-definition>
Appendix 5 Java Coding-Style Conventions 767
variables. On the other hand, if a mutator performs validation on a parameter prior to assigning it to its associated instance variable, then it is not trivial, and you should include a prologue with it. The same reasoning applies to a constructor. A simple-assignment constructor should not have a prologue. A vali- dation constructor should have a prologue.
2. In the interest of grouping similar things together, you should omit asterisk lines between trivial con- structors, and you should omit asterisk lines between mutators and accessors.
Assume that a class contains two trivial constructors, several mutator and accessor methods, and two other simple methods. Here’s the framework for such a class:
<class-heading> {
In the above framework, note that there are no descriptions for trivial constructors, accessors, or muta- tors, or for simple methods. Note also that there is a line of asterisks above the first mutator, but not above the subsequent mutator and accessors. Those omissions help to make a program more readable by grouping similar things together. Also note that there are no comments above each of the two simple methods at the bottom of the class, but there are lines of asterisks.
3. Place local variable declarations immediately below the method heading. Do not place local variable declarations within the executable code.
Exception: Declare a for loop index variable within its for loop header.
















































































   799   800   801   802   803