Question:
I have classes to tailor reports. These reports really fit a matrix, i.e.
there are two logical ways to structure them.
For example: one way is by subject (Twheels, with descendants Tcars,
Ttrains, etc. and each of these splitting further into subclasses). The
other way is by language.
Ideally, I'd like to create an object for a report on cars in English, and
one for trains in French.
Clearly, there are many similarities between the reports of a same language
(like all the headers, truncation rules, etc.) and also, there are many
similarities between cars, race cars and oldtimers.
I would like to access properties to do with the language, as well as
properties of the subject.
(In reality it is not about cars and languages, but the problem is the
same.)
Any suggestions ?
Answer:
Interfaces. You can have a list of interfaces that declare the relevant
methods and properties for your languages, and a list of interfaces for
your subjects, and every report can mark itself as implementing one
interface from either list.
Where this breaks down is in code re-use, because the obvious
implementation
simply reiterates similar code in every class. You can get around that by
delegating interfaces to objects that implement a language or subject
interface for a report, but it's rather a hairy topic
Submit Your
Own Answer!