Graphics Reference
In-Depth Information
Figure
.
.
Mosaic plot example
We have classes that implement
DataModel
and have components of
Real-
DataModel
to read data fromfiles.
CSVDataModel
can read data froma file that
stores data in the CSV format.
ExcelDataModel
can read a Microsot Excel data
formatfile.heyarealmostthesameas
RealDataModel
exceptforthebehaviorof
the
setReal
method. hetraditional way of realizing them is touse an inheritance
mechanism. However, we use the “Decorator” design pattern to realize these classes
using a composition technique.
hedecoratorpattern attaches additional responsibilities toanobjectdynam-
ically. Decorators provide a flexible alternative to subclassing for extending
functionality (Gamma et al.,
).
In other words, the decorator pattern provides a class to add new capabilities to an
original class, and passes all the unchanged methods of the underlying class to the
new class.
We realize
CSVDataModel
by decorating
RealDataModel
.
CSVData-
Model
hasthe
RealDataModel
objectinit.
setReal
of
CSVDataModel
reads
data from a CSV file and sets them to a two-dimensional real array. hen
setReal
of the
RealDataModel
object is used and data are stored to it. Other methods
of
CSVDataModel
are all realized by delegation to the
RealDataModel
object.
hisisatypical decorator pattern andatypical useof thecomposition technique. See
Fig.
.
.