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. NamingThe name of a storage class should follow the rules for naming classes:
StudentRecord ListNode GridCell MatrixElement MapElement
Record Element Cell Node Item
Storage classes must be commented with a description and an indication of their visibility. ConstructorA storage class should only include a constructor that either takes no arguments class StudentRecord: def __init__( self ): # Do this. self.idNum = 0 self.firstName = None self.lastName = None self.gpa = 0.0 or arguments comprised of all or a subset of the data fields defined by the class class StudentRecord: def __init__( self, idNum, firstName, lastName ): # Or do this. self.idNum = idNum self.firstName = firstName self.lastName = lastName 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 class StudentRecord: def __init__( self, line ): # Don't do this. lineParts = line.split() self.idNum = int(lineParts[0]) self.firstName = lineParts[1] self.lastName = lineParts[2] self.gpa = 0.0 Data AttributesThe data fields or attributes of a storage class should:
|