Storage Classes

Storage classes are used to store a structured or multi-component data record. By using a storage class, the individual data components can be referenced by name instead of using a tuple or list structure and referencing the components by index. A data field name provides a more meaningful indicator of the type of data and its purpose as compared to a simple integer index value.

Naming

The name of a storage class should follow the rules for naming classes:

  • The name should be descriptive of the data actually stored in instances of the storage class.
    1.   StudentRecord   ListNode   GridCell   MatrixElement   MapElement
  • The name should consist of more than one word and typically ends with one of the following nouns:
    1. Record    Element   Cell    Node    Item
  • Do not name a storage class Storage or Record.

Storage classes must be commented with a description and an indication of their visibility.

Constructor

A storage class should only include a constructor that either takes no arguments

  1. class StudentRecord:          
  2.   def __init__( self ):      # Do this.
  3.     self.idNum = 0
  4.     self.firstName = None
  5.     self.lastName = None
  6.     self.gpa = 0.0

or arguments comprised of all or a subset of the data fields defined by the class

  1. class StudentRecord:          
  2.   def __init__( self, idNum, firstName, lastName ):      # Or do this.
  3.     self.idNum = idNum
  4.     self.firstName = firstName
  5.     self.lastName = lastName
  6.     self.gpa = 0.0

No processing or executable statements other than assignments should be performed within the constructor of a storage class. For example, the following should not be done

  1. class StudentRecord:          
  2.   def __init__( self, line ):      # Don't do this.
  3.     lineParts = line.split()
  4.     self.idNum = int(lineParts[0])
  5.     self.firstName = lineParts[1]
  6.     self.lastName = lineParts[2]
  7.     self.gpa = 0.0

Data Attributes

The data fields or attributes of a storage class should:

  • have meaningful names as related to the data they store,
  • be public since they are directly accessed by the code that uses them.
  July 4, 2026 at 06:09 AM