Design Patterns Java™ Workbook

(Michael S) #1
Appendix B. Solutions

import java.io.*;
public class OoStringReader extends StringReader
{
public OoStringReader(OoString ooString)
{
super(ooString.getString());
}
}


Note that operations that expect a StringReader object will accept an instance of
OoStringReader.

D. False. There is no obligation to support all the operations of the class you delegate to.
The getString() method of OoString lets clients extract the underlying String
object if they need an operation that OoString does not supply.
E. True. In particular, Java compilers will interpret a sequence of characters between
double quotes as an instance of String:


String answer = "Yep, strings are special";

Free download pdf