Lecture Notes on Object-Oriented Programming

The Quality of Classes and OO Design

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

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).