For an assignment, I have to find out which of the Gang of Four design pattern the classes java.io.Reader
and its subclasses java.io.PushbackReader
, java.io.BufferedReader
and java.io.FilterReader
were built with.
According to this post, the design pattern would be the Decorator Pattern. This only makes sense to me if PushbackReader
, BufferedReader
and FilterReader
can be decorated to be used at the same time, creating effectively a BufferedPushbackFilterReader
. Is that the idea?
Best Answer
Yes, you can indeed decorate them like that. Just consider the following
That would decorate an original reader to
FilterReader
andReader
are base classes in the hierarchy...