They have no business accepting the base class interface then.
There are cases of program design necessity. For instance, it can be
pair of classes developed together: "creater"-"user". They improve
integrated base functionality of existing program, so no one unit of
existing (and may be compiled) program do not know about new derived
classes and "creater"-"user" must communicate "over" pointer to base
class.
Huh? Decorator is a way to extend functionality through *composition*.
It implements the interface of the decorated object and becomes a
mediator, performing extra functionality as needed.
It is true, the "implementaion" of the pattern goal can be done by
"composition of the decorated object", but "composition" can be not
enough.
You have written "implements the interface of the decorated object".
Not only "implement", it is better to say "inherit the interface of the
decorated object or its base class". It is good if you can limit
decorator interface by interface of its decorated object.
But sometimes it is really imposible - we need to adjust own decorator
properties (they have no sense and they do not exist for decorated
object) _after_ decorator have created, so we need extra "decorator"
interface and a way to get the interface from pointer to the class of
"decorated" object.
There is an any object container in boost. I don't see a whole lot of
use in that object per se. I have used the constructs it uses to do
its job in some stuff I worked on wrt units and dimensional
analysis.... to allow an object of any unit type to exist (when units
are separate static types) and I didn't use any of the casting or type
identification stuff.
"object per se"? "wrt"? What use what? Sorry, I do no know english well
and do not understand what do you speak about
Besides stuff like that I don't see how it has
much use in well designed software....
I do not understand the goal of the special "stuff", you have spoken
about, but i can describe the design pattern "pointer to indefinite
class". In order to describe any design pattern, you need to define at
least three things:
1. context to apply the pattern
2. the goal of the pattern
3. the way of the pattern implementation
For design pattern "pointer to indefinite class":
1. not shared ot local-shared libraris of program with many quantity
(for example 100)
of different types and classes, which must be placed in lists, arrays
etc
2. decrease code size
(do not want to create 100 equal copies of
lists, arrays etc) by making single class for each type of container
(list, array etc) to keep "object of indefinite class", by allowing
single copy for each type of "algorithm" methods, based on "interface
of indefinite class".
3. i think it is out of "comp.lang.c++" topic and "How to judge if two
objects have the same type" too, but say some words:
a)"interface of indefinite class" depends from concrete program (so we
get "local-shared" pattern context), for example, the easy interface
are virtuals: create/copy/clone constructors and destructor.
b)we inherite all "containerable" types of the program from
program-global base class "indefinite class"
c)type check and type-dependent interdace for "remove/insert_correct
type_object" we make with template<> (template<> inherit
"concrete_container" from "container_of_indefinit_class" ), so we can't
get "runtime bad_cast" and each template<> copy of code do chiefly only
dynamic_cast (so can not be optimized more).