©2005 Felleisen, Proulx, et. al.
Unions
Consider this the following problem:
Develop a program that creates a gallery from three different kinds of media: images (gif), texts (txt), and sounds (mp3). All have names for source files and sizes (number of bytes). Images also include information about the height, the width, and the quality of the image. Texts specify the number of lines needed for visual representation. Sounds include information about the playing time of the recording, given in seconds.
Develop a data representation for these media. Then represent these three examples with objects:
an image, stored in flower.gif; size: 57,234 bytes; width: 100 pixels; height: 50 pixels; quality: medium;
a text, stored in welcome.txt; size: 5,312 bytes; 830 lines;
a music piece, stored in theme.mp3; size: 40960 bytes, playing time 3 minutes and 20 seconds.