"vsgdp" <he***@null.comwrote...
>I have a set of brush classes that inherit from Brush. They override a
pure virtual paint method. When the user selects a new brush, I just have
a Brush pointer point to an instance of the particular selected type of
brush.
The problem is that some brush settings don't apply to every kind of
brush.
Like which? And if the brushes are not truly *extending* the base Brush,
why are they deriving from it?
So it is difficult to set the particular brush property with the abstract
brush pointer.
What do you mean by "to set the particular brush"?
I see two ways to handle this:
Add a virtual "set" function that takes an AllBrushProperties structure
(some properties will be unused depending on the brush) so that each brush
can update itself correctly.
Use runtime type checking and downcast to the type to call the appropriate
set method.
I don't really like either as it sort of ruins my otherwise clean
polymorphic system.
"Clean"? Are you sure? You know, there's much to be said about deriving
a PhoneNumber class from a String class, for example. In my book public
inheritance is not the right thing for those. A phone number, although can
be represented by a string, is not a true *extension* of it. It seems that
you are looking at your polymorphic system through rosy glasses.
Another possibility is to have a *polymorphic* BrushPropertySetter class
and have every Brush descendant present a pointer to its own "Setter". I
don't know (yet) what properties you have that are not common, but each
of the brush-specific setters can present its own interface to the user,
and the user then sets certain properties that will be used to update the
correct brush (or something like that anyway).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask