UMBC CMSC202, Computer Science II, Fall 1998,
Sections 0101, 0102, 0103, 0104
9. Redesigning Classes
Tuesday September 29, 1998
[Previous Lecture]
[Next Lecture]
Assigned Reading: 5.1-5.7
Handouts (available on-line):
Programs from this lecture.
Topics Covered:
- Exam 1 Topics
- Detailed discussion on the design of the BString class. Some of the
design goals were:
- ease of use
- lots of error checking
- compatibility with char * strings
- We looked at some client programs that use the BString class
(see header file):
- Use overloaded << and >> operators.
Program and sample run.
- Use of constructors, + for concatenate, the [] operator,
overloaded comparison operators, automatic "user-defined" type conversion.
It turns out that this use of automatic type conversion from BString to
char * causes a memory leak.
Program and sample run.
- The [] operator returns a reference to char. So it
is possible to assign new values to the characters in a BString object. We
use this feature to convert a string to all upper case.
Program and sample run.
- We use the >> operator to read in a file name,
then dump the contents of that file to the screen. Note that
the >> operator can be used for file I/O as well
as console I/O. Also, note that the correct use of the type
conversion operator (without causing a memory leak) is awkward.
Program and sample run.
- Finally, we looked at the
implementation of the BString class in detail and discussed the
ramifications of various design and implementation decisions.
- Next lecture, we will quickly
look at a second implementation of the BString class that
fixes some of the problems with the first implementation.
(see header file
and implementation.)
[Previous Lecture]
[Next Lecture]
Last Modified:
22 Jul 2024 11:28:48 EDT
by
Richard Chang
Back up
to Fall 1998 CMSC 202 Section Homepage