On Sep 16, 2:11 pm, Andreas Dehmel <blackhole.
On Wed, 16 Sep 2009 00:52:24 -0700 (PDT), Stuart Redmann wrote:
Stuart Redmann wrote:
and give us a call if you've survived basic editing
facilities without going insane; and then there's years
of maintenance which'll definitely finish the job...
You'd need an awful lot of dynamic casts for this to be
more readable in situations like this. This approach may
work for some specific problems, but as a general design
advice it's just as poor as bloating the base interface
with virtual functions for all eventualities.
I don't understand why the problem space, drawing
programs, should be prone to dynamic_casts. Could you
please elaborate what technical/ maintainance reason there
is why we have to use dynamic_casts in drawing programs?
I'd really be interested.
The maintenance reasons against multiple lists for something
like this I explained above. With a single list, the need
for dynamic casts arises when you actually need to address
properties of specific objects. Such as the radius of a
circle or the control points of a bezier curve, neither of
which belong into the base interface because they're not
common properties of all shapes. It gets really great for
something like "Does A intersect B" (and I don't mean
bounding boxes but the real deal which needs to know the
exact properties of both shapes, e.g. circle and bezier
curve). Trying to do this with N containers and without
dynamic casts would mean N^2 implementations of the entire
code sequence from retrieving the objects from their
respective containers based on some criteria (usually not
type-related) to the actual evaluation of the intersection
function (N functions, actually, one for each type). The
only feasible way to do this would be heavily templated
code, which'll still create massively bloated object code.
Compared to all this, occasional dynamic casts are a
ridiculously small price to pay.
Another example would be GUI libraries. They all have
different widget types and sometimes need to address
type-specific properties. I've seen a few of them, but I've
never come across one which keeps its widgets in different
lists by type. It'd be pretty much the worst possible design
in situations like these. It probably is for most
non-trivial problems, actually.