Friday, July 17, 2009

Object-Oriented Naming Convention

Object oriented programming languages (Java, C#, etc.) follow some fairly standard naming conventions with respect to classes, variables and methods.

Class names always start with a capital letter, and objects/variables and methods start with a lower case.
  • Classes: Object, Action, Date, GregorianCalendar
  • Objects: size (of class Dimension), date (of class Date), name (of class String)
  • Variables: year, month, length
  • Methods: indexOf, substring
Normally, spaces (even if syntactically allowed) and underscores are not used. Instead, names consisting of multiple words are delimited by using a capital letter to start each word. This is sometimes refer to as "camel case" because it looks like a camel with humps. An exception is variable meant to be constants.
  • Constants: BorderLayout.BEFORE_FIRST_LINE, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
Method names often start with a verb (action) followed by the target object name.
  • Method names that start with a verb or action: setVisible, isSelected

No comments:

Post a Comment