R
Ross A. Finlayson
I wrote up a little program that generates C++ from a simple input
format, a list of relations. Basically I'm trying to understand
"composition hierarchy" vis-a-vis "inheritance hierarchy."
The inheritance hierarchy has a mechanism in C++ to describe it, class
inheritance, but there doesn't seem to be built-in support for
composition hierarchy. That's no exactly so, but to iterate over the
contained elements of a class requires the implementation of an
iterator, and for nested composition as a tree, depth or breadth first
iterators or iterators to given depths or heights.
So I began with simply a tree to represent a composition hierarchy, then
got to having each node (class type) having as well a list of child
elements to represent inheritance hierarchy, then got to having multiple
parents in the tree for inheritance, and then also there could be
multiple parents in composition, along the lines of different uses of
the objects.
Part of the notion is to automatically generate methods conforming to
interface or convention for standard library interaction. For example,
there might be interfaces implemented for comparable and then
ostreamable, where ostreamable would implement simple ostream inserters
by iterating over the containment hierarchy.
Implementing istreamable for istream extractors is a little more
involved, in terms of notions like parseable, recognizeable, and
rejectable in terms of acceptable, towards having a decomposable parser,
decomposed into each class having its own implementation, then composed
in the composition hierarchy, probably using parser expression grammars,
and conceivably specialized in the composite classes.
This is a circuitous route towards implementation of a statistics
gathering parser, or rather, statistics gathering over the composition
hierarchy. Besides automatically generating a composition hierarchy and
inheritance hierarchy off of a terse specification, I also want there to
be generated a variety of statistics, where basically all these object
types represent data embodied in some form. The statistics are
variables for input into statistical inference algorithms.
Anyways for now in implementing this little code generator, where in
terms of the upwards and downwards composition and hierarchy trees from
each node, each type, with each link having various attributes, then
that is all in terms of class composition and inheritance, using only
the type names, at some point I have to enumerate methods and
implementations, besides deconstructing the implementations towards
algorithmic recomposition of the algorithms, the attributes get
arbitrary. There isn't a convenient dynamic mixin facility in C++,
which would be convenient. So, I need to figure out more about the
attributes of inheritance and composition relations.
Anyways I wonder if there are some examples of generating iterators over
a composition/containment/aggregation hierarchy. This is about typing
each element contained in a composition hierarchy to provide iterators
over its elements, then it could very easily be treated as a tree in
graph algorithms, in an automated manner.
So: inheritance hierarchy, use built-in inheritance mechanism and
generally use pointers to allow polymorphism. Composition hierarchy,
good practice?
Thanks,
Ross F.
format, a list of relations. Basically I'm trying to understand
"composition hierarchy" vis-a-vis "inheritance hierarchy."
The inheritance hierarchy has a mechanism in C++ to describe it, class
inheritance, but there doesn't seem to be built-in support for
composition hierarchy. That's no exactly so, but to iterate over the
contained elements of a class requires the implementation of an
iterator, and for nested composition as a tree, depth or breadth first
iterators or iterators to given depths or heights.
So I began with simply a tree to represent a composition hierarchy, then
got to having each node (class type) having as well a list of child
elements to represent inheritance hierarchy, then got to having multiple
parents in the tree for inheritance, and then also there could be
multiple parents in composition, along the lines of different uses of
the objects.
Part of the notion is to automatically generate methods conforming to
interface or convention for standard library interaction. For example,
there might be interfaces implemented for comparable and then
ostreamable, where ostreamable would implement simple ostream inserters
by iterating over the containment hierarchy.
Implementing istreamable for istream extractors is a little more
involved, in terms of notions like parseable, recognizeable, and
rejectable in terms of acceptable, towards having a decomposable parser,
decomposed into each class having its own implementation, then composed
in the composition hierarchy, probably using parser expression grammars,
and conceivably specialized in the composite classes.
This is a circuitous route towards implementation of a statistics
gathering parser, or rather, statistics gathering over the composition
hierarchy. Besides automatically generating a composition hierarchy and
inheritance hierarchy off of a terse specification, I also want there to
be generated a variety of statistics, where basically all these object
types represent data embodied in some form. The statistics are
variables for input into statistical inference algorithms.
Anyways for now in implementing this little code generator, where in
terms of the upwards and downwards composition and hierarchy trees from
each node, each type, with each link having various attributes, then
that is all in terms of class composition and inheritance, using only
the type names, at some point I have to enumerate methods and
implementations, besides deconstructing the implementations towards
algorithmic recomposition of the algorithms, the attributes get
arbitrary. There isn't a convenient dynamic mixin facility in C++,
which would be convenient. So, I need to figure out more about the
attributes of inheritance and composition relations.
Anyways I wonder if there are some examples of generating iterators over
a composition/containment/aggregation hierarchy. This is about typing
each element contained in a composition hierarchy to provide iterators
over its elements, then it could very easily be treated as a tree in
graph algorithms, in an automated manner.
So: inheritance hierarchy, use built-in inheritance mechanism and
generally use pointers to allow polymorphism. Composition hierarchy,
good practice?
Thanks,
Ross F.