0% found this document useful (0 votes)
55 views1 page

Repinvar

The document discusses natural representations for classes. It provides examples of how a queue is commonly represented using a front and back to enter and exit items stored in order. The representation, such as using an array to store queue items, is a design choice that should be formalized. An included representation invariant explains how the abstract concept is represented by the data structures and variables used, serving as a complement to the class comment.

Uploaded by

api-3697260
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views1 page

Repinvar

The document discusses natural representations for classes. It provides examples of how a queue is commonly represented using a front and back to enter and exit items stored in order. The representation, such as using an array to store queue items, is a design choice that should be formalized. An included representation invariant explains how the abstract concept is represented by the data structures and variables used, serving as a complement to the class comment.

Uploaded by

api-3697260
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 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…

You might also like