icon-mobile-menu.svg

Lecture Notes on Object-Oriented Programming

Naming Conventions

This collection of notes on OOP was never meant to stand alone. It also represents a view of OO circa early to mid 1990s. Some people still find them useful, so here they are, caveat emptor. Special thanks to Gilbert Benabou for taking to time to compile the first printable version of this document and inspiring us to provide it.

[ PDF ] Printable Version

Table of Contents
  1. Introduction: Motivation for OO
  2. The OO Paradigm
  3. Visualizing Program Execution
  4. Naming Conventions
  5. The Object Model
  6. Abstraction and Identity
  7. Messaging
  8. Encapsulation & Modularity
  9. Hierarchy
  10. Object-Oriented Typing
  11. OO Concurrency & Persistence
  12. OO Development Process
  13. OO Analysis Techniques
  14. Pitfalls in OO Analysis
  15. UML Notation
  16. CRC Cards
  17. OO Class Relationships
  18. Object Oriented Aggregation
  19. Object Oriented Interitance
  20. Other Object Oriented Class Relationships
  21. Object Oriented Instantiation
  22. Object Oriented Polymorphism
  23. Review of OO Programming
  24. The Quality of Classes and OO Design

A standard naming scheme for classes, objects, instance variables, and methods is important. Here are two alternatives.

Naming Scheme 1

Class names: concatenated words each starting with upper case.

  • Account, BankAccount, CashDispenser, SortedIntegerQueue

Objects, ivars, methods: concatenated words, first word all lower case, subsequent words starting with upper case.

  • balance, shareBalance, count, quantityOfFives
  • list, nodeList, account, newAcct
  • deposit, balance, objectAt, dispenseMoney

Naming Scheme 2

Class names: concatenated words each starting with upper case.

  • Account, BankAccount, CashDispenser, SortedIntegerQueue

Objects: lower case separated by underscores.

  • list, node_list, account, new_acct

Ivars: lower case separated by underscores.

  • balance, share_balance, count, quantity_of_fives

Methods: concatenated words, first word all lower case, subsequent words starting with upper case,

  • deposit, balance, objectAt, dispenseMoney

Hungarian Notation

Everything has a tag that identifies it. This tag is appended to the name, so, for example, an ivar named height of type float might be called height_i_f. Similarly, every class ends in the capital letter "C".

This scheme forces you into the solution space (programming language) and distracts you from the problem space.

Names are vitally important, for the same reason they are important in non-OO languages, but also because of the anthropomorphic nature of OO programming.

It is common in OO languages to name things with the name of the class and a definite or indefinite article ( Control, aController; View, theView). These names are fine when something more appropriate can't be found (List, employees).