Вы находитесь на странице: 1из 1

Classes Have Natural

Representations
• A Queue is a representation of a line:
– Have a front (head) and back (tail)
Representation Invariants – Enter at the tail (enqueue)
– Leave from the head (dequeue)
– Remain in order of insertion
Helping to Design Good Classes
• You decide how representation is done
– What data structure to use.

Representation is the Design Representation Invariant


• How to represent a Queue: • Included as a comment in the .CPP file
– The data is stored in an array: • A set of statements about the data
• The “head” is A[0]
• Explains how the abstract concept is
• The “tail” is A[size-1]
• Data stored in order of insertion from A[0]…A[size-
represented by the data structures used
1] • Compliment comment, “class comment”,
• This representation is what you design explains the abstract concept in the .h file
• Need to formalize the representation

What to Include Example


• Explains member variables only • Stack:
• Explains how variables / data structure A “pile” where objects are inserted at the top,
represent abstract idea of the class and removed from the top. The order of the
objects’ removal is the inverse of the order of
• Explains limits on the variables insertion.
• Explains how variables interact with each
other Now , the representation invariant…

Вам также может понравиться