Entity Class Checklist (conforms to the IRS Java Coding Standards) 0) Before you start coding an Entity class, you need to know how many fields, and for each field the name the type the initial value the min the max the content rules 1) The Class name should an a singular noun or noun phase 2) The name should be in CamelCase w/ a starting uppercase letter 3) All names class/field/method should be meaningful 4) Class scope fields should be declared at the start of the class 5) Every Entity class should have a "default" Constructor (zero arguments), overloaded Constructors may be added 6) Constructors should be coded after the class scope fields and before other methods 7) Class scope fields should be declared as private, if a field is a constant (final) it may be declared as public 8) Class scope fields should have public get/set methods, read-only fields may have a get method only write-only fields may have a set method only 9) Any business rules must be in the set methods. if there are rules about accessing a field, these rules go in the get method 10) Constructors should initialize and document all fields 11) All field names should be in CamalCase w/ a starting lowercase letter 12) All methods names (except Constructors) should be in CamalCase w/ a starting lowercase letter 13) All public/protected/ classes/fields/method must be documented using JavaDocs 14) All class should have a copyright comment section at the top See the IRS coding standard (3.9.1) for a sample IRS copyright 15) All Entity classes should implement java.io.Serializable, and have a static serialVersionUID, I start development w/ version 1 of this class, after it is deployed, and the class comes back to me for maintenance or enhancement, then I change the version number to 2 16) Any final field (constent) should be initialized, and the name should be all uppercase using SNAKE_CASE (Letters and underscores) 17) All Entity classes should override 3 methods from class Object toString() -> provide a custom string for printing this object hashCode() -> is used internally by Java to find the object in memory equals() -> (is paired with hashCode(), if you code an equals() you should also code a hashCode(), Java uses them together) is used to compare 2 objects to see if they are the same 18) All Entity classes should be in Packages (folders) at the IRS package names are: gov.irs... in this classroom we will use: org.example.. 19) The Constructor should call the set methods to initialize the fields that way all the Business Rules are checked, and logging happens 20) The JavaDocs for the set methods should documents all the Business Rules 21) Every method should include Logging, the log messages should be secure Debug level logging for tracing the flow Error level logging for finding issues etc. 22) JUnit test must be written for each business rule Here is how I create an Entity class 1) I make sure the project and package exist 2) I create a new class 3) I add the fields 4) I ask Eclipse to Generate the get/set methods for me Source menu (I can Format via Source menu anytime) 5) I ask Eclipse to Generate a Constructor 6) I ask Eclipse to Generate a toString method 7) I ask Eclipse to Generate hashCode and equals methods ------ here I start writing code ------ 8) I finish the Constructor initalize all the fields I need JavaDocs for the Constructor 9) One-by-One, I finish all the get/set methods I need JavaDocs in the Set methods I need to check the business rules I add the log statements I write and run the JUnit tests for this method As a milestone for Entity class creation: For Each Field I should have: private field public get/set in the set I have the checks for the business rules JavaDocs JUnit Tests At any point in the Entity class development, I can 1) Generate JavaDocs to check my documentation 2) Generate Code Coverage to check my JUnit coverage I can run these using Eclipse, or I can run these using Maven for Eclipse I use the Project menu to generate JavaDocs I right click and do Coverage As... to run JUnit Test Coverage for Maven I right click the Project and Run As.. Maven Build (using the site Goal) Maven generates the Project Reports (Eclipse does not)