Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In general, we are following the recommendations in the book: The Elements of Java Style. Please be familiar with the conventions in that book, as it will result in less reformatting of code later. (Such reformatting makes it harder to detect actual coding changes.)

Configure your Integrated Development Environment to assist you in following the style guidelines: Coding Standards - IDE Settings

Class Structure

For the most part, classes should be laid out in the following order:

  • LOG

  • fields

  • constructors

  • overridden methods (public)

  • protected/private methods

  • getters and setters with logic

  • getters/setters with no logic

Use of Braces

In almost all cases, braces should be used when creating blocks. It is too easy to introduce bugs into the system by omitting braces for single-line clauses, especially if-then-else setups. (This is one of those cases where indentation comes into play, if lines after the first are also indented, a developer reading the code might assume that those lines are part of the else clause.

...

Entity

Naming Conventions

Good Examples

Incorrect Examples

package

  • reverse name of internet domain and suffix the package name
  • use a single, lowercase word as each package name
  • meaningful abbreviations can be used

org.apache.log4j.logger
org.kuali.ole.module.ld
org.kuali.ole

org.kuali.YearEnd

class

  • use nouns when naming classes
  • use full description with the first letters of all words capitalized
  • pluralize the names of classes that group related attributes, static services and constants

LedgerPendingEntry
BalanceType
PendingEntryGenerator
LaborConstants

BalanceTyp

interface

  • use nouns or adjectives when naming interfaces
  • use full description with the first letters of all words capitalized
  • avoid using suffixes like "Interface", "Intf", or "I" in the name (preference)

TransactionPoster
LookupResultsSelectable
AccountInterface
LedgerEntryService

PostTransaction
AccountIntf

enum

  • use nouns when naming enumerations

Weekday 


enum values

  • use full description with uppercase words separated by underscores for enum constants

MONDAY
DIVIDED_BY 


method

  • use active verbs when naming methods
  • use full description with lowercase of the first word and the first letters of all subsequent words capitalized
  • follow java bean conventions for naming property accessor and mutator methods

save()
updateLedgerBalance()
getLedgerBalance()
setLedgerBalance()
isValidAccount() 


variable

  • use nouns when naming variables
  • use full description with lowercase of the first word and the first letters of all subsequent words capitalized
  • prefix the variables of type Boolean with “is” , “can” and so on to indicate their types
  • pluralize the names of collection references

documentTypeCode
financialObjectCode
entryIterator
isNewAccount
canOpenNewAccount

findTypeCode
foc
entry_iter
newAccount
openNewAccount
subFundGroupCodes

constant

  • constants should be defined as static final variables
  • use nouns when naming constants
  • use full description with uppercase words separated by underscores
  • if the constants are part of a closed set, consider using an enum

FISCAL_YEAR

FROM
fiscalYear
Fiscal_Year

...

Examples of Constant Classes: 


Constant TypeGlobal KFS ClassModule-Specific class exampleDescription/Usage
Constants

org.kuali.kfs.sys.KFSConstants

org.kuali.kfs.module.purap.PurapConstantsUsed to define general constants (don't fit in one of the categories below) for the system or module.

KeyConstants

org.kuali.kfs.sys.KFSKeyConstantsorg.kuali.kfs.module.purap.PurapKeyConstantsHolds error key constants that are global or module-specific.
PropertyConstantsorg.kuali.kfs.sys.KFSPropertyConstantsorg.kuali.kfs.module.purap.PurapPropertyConstantsHolds property name constants that are global or module-specific.

ParameterConstants

org.kuali.kfs.sys.KFSParameterKeyConstantsorg.kuali.kfs.module.purap.PurapParameterConstantsHas names of parameters associated globally or with a module (inner classes can be used to organize those parameters which don’t fit with the big four components of All, Batch, Document, and Lookup).
WorkflowConstants 
org.kuali.kfs.module.purap.PurapWorkflowConstantsHas node names and application document statuses (inner classes can be used here to differentiate between nodes and statuses used on different documents, like what PurapWorkflowConstants does).
AuthorizationConstantsorg.kuali.kfs.sys.KfsAuthorizationConstantsorg.kuali.kfs.module.purap.PurapAuthorizationConstantsContains names of edit modes (again, inner classes to separate by document type is fine) and special permission names which need to be called...and in very very rare cases, role names.
KimAttributesorg.kuali.kfs.sys.identity.KfsKimAttributesorg.kuali.kfs.module.purap.identity.PurapKimAttributesSpecial case that holdes constants for KIM attributes as well as instance variables, setters and getters for those attributes.

...

Service

Purpose

Sample Methods

Standard KNS Services

 

 



BusinessObjectService

General purpose service to retrieve and persist business objects. This service eliminates the need for custom DAOs and services for basic CRUD operations.

Code Block
save( businessObject ) 
findByPrimaryKey( class, primaryKeyMap ) 
findBySingleFieldPrimaryKey( class, primaryKeyValue ) 
findMatching( criteriaMap ) 
countMatching( criteriaMap )

LookupService

Service for performing more complex lookups of business objects. Criteria maps passed to this service can contain special characters in the lookup values which can perform and/or/between/greater than/less than operations. This also can be used to reduce the need for OJB-specific query code.

Code Block
findCollectionBySearch( class, criteriaMap )

MailService

Used to send email messages.

Code Block
sendMessage( MailMessage )

DateTimeService

Use to obtain the current date/time and parse/format dates between String and Date objects.

Code Block
getCurrentDate() 
getCurrentSqlDate()

Data Dictionary Services 

 



DataDictionaryService

General purpose service to obtain information about business objects, documents, and their attributes from the data dictionary. These calls are lower level than either of the services below. Only use these calls if you can't get the information from one of the services below.

 


BusinessObjectDictionaryService

Specialization of the above service to help answer more complex, but common, questions needed about business objects, mainly for implementing the KNS framework. 


MaintenanceDocumentDictionaryService

Same as the above, but for maintenance documents.

Code Block
Class getMaintainableClass(String docTypeName) 
String getDocumentTypeName(Class businessObjectClass) 
Class getBusinessObjectClass(String docTypeName)

Workflow Wrapper Services

 

 



DocumentService

Primary KNS service for interacting with documents. This service should be used whenever possible instead of accessing KEW services.

Code Block
Document getNewDocument(String documentTypeName) 
boolean documentExists(String documentHeaderId) 
Document getByDocumentHeaderId(String documentHeaderId) 
Document saveDocument(Document document) 
routeDocument(...) 
approveDocument(...) 
sendAdHocRequests(...)

Information Services

 

 



ConfigurationService

Used to pull configuration properties (mostly from configuration.properties).

Code Block
String getPropertyValueString(String key)
boolean getPropertyValueAsBoolean(String key)

ParameterService

Used to pull parameters from the KRNS_PARM_T table on the Rice server.

Code Block
parameterExists(...) 
getParameterValueAsBoolean(...) 
getParameterValueAsString(...) 
getParameterValuesAsString(...) 

...