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

                304 Chapter 8 Software Engineering
The last point can best be understood with an example. Here is a nicely written for loop header: for (int i=0; i<10; i++)
Note that there are no spaces surrounding the = operator or the < operator. Why is that good practice? Be- cause the for loop header is inherently complex. In order to temper that complexity, we add visual cues to compartmentalize the for loop header. More specifically, we consolidate each section (no spaces within each section), and we insert a space after each semicolon to keep the three sections separate.
Grouping Constructors, Mutators, and Accessors
For short, obvious methods, you should omit descriptions. For example, mutators and accessors are short and obvious, so you should omit descriptions for them. Constructors are sometimes short and obvious, but not always. If a constructor simply assigns parameter values to associated instance variables, then it is short and obvious and you should omit a description for it. If, on the other hand, a constructor performs non- obvious input validation on user-entered values prior to assigning them into associated instance variables, then you should include a description for the constructor.
In the interest of grouping similar things together, we recommend omitting the line of asterisks be- tween mutators and accessors and between short obvious constructors. Assuming that a class contains two short, obvious constructors, several mutator and accessor methods, and two short, obvious other methods, here’s the framework for such a class:
<class-heading> {
Apago PDF Enhancer
<instance-variable-declarations>
//*********************************************************
<constructor-definition>
<constructor-definition>
//*********************************************************
<mutator-definition>
<mutator-definition>
<accessor-definition>
<accessor-definition>
//*********************************************************
<method-definition>
//*********************************************************
<method-definition> }














































































   336   337   338   339   340