Hello everybody,
i have a problem related to the design of a composite structure. I have an Expression abstract class that describes a generic mathematical expression. The idea is that an expression can be an atomic expression (like "x" or "3") or some kind of aggregation of atomic expressions (like summatories, productories, exponentiations, etc). That turns out to be well described by a Composite pattern, so for instance the class Summatory inherits from OperationTerm, that in turn inherits from Expression, and contains a list "augends" of Expression terms.
Everything is fine until I try to specialize some of these expression on the base of some properties; for example, if an Expression is made up by a Summatory of Monomial terms, it should be "labelled" as a Polynomial, in order to optimize certain kinds of operations (like integrals or derivatives) in a way that is transparent to the client code (that should handle only Expression objects).
Anybody has an idea on how I could design this kind of structure (possibly in an extensible way)?