|
Boost : |
From: Christophe Meessen (christophe_at_[hidden])
Date: 2002-11-21 09:31:55
Hello,
I am sorry because I don't know of the other method referenced as Loki's
factory.
Regarding Anthony's proposal we should indeed make a difference between
a factory and a metaclass or virtual constructor though both a tightly
related.
Don't misunderstand me. The proposal of Anthony is great and deserves to
be added to the boost library. But I need additional functionality.
What I need is something like the factory method design pattern. It is a
method that will construct different types of class instances according
to some key information. It could be the class name string, an integer
or anything else. It is trivial to implement using Anthony's virtual
constructors.
Though I needed a bit more than that. I wanted a factory that would be
able to construct objects defined in different libraries and eventually
in DLLs. The user would only have to link with the library or load the
DLL to make its classes known to the object factory. I need a plug and
play solution that would simplify lives of programmes. If this works
with DLLs (though I didn't test it) we would have a plugin manager
straight out of the box.
This is what I did in my Factory class. By use of static methods, and
static method variables the new virtual constructor would automatically
add it self to thefactory map. When the buoldObject is called, it would
look into the map to call the appropriate virtual constructor. The
destructor of the virtual constructor would remove itself from the
factory map. The factory and each virtual method is a singleton object.
I need that for some program with internal dynamic dataflow
organisation. The configuration is read from a file and evetually
modified at run time. The configuration file contains the class name
that should be used as key to pass to an object factory. I wanted that
the user could add new type of dataflow objects by simply adding a DLL
or eventually by linking with the library but without needing to tuch
the code. I have the impression that such type of use cases is not so
uncommon. It is the same when a user want to use DLLs as plugins, or to
read data from a database or whatever container or when objects have to
be send over network. In all case an object factory is required and it
is desirable that one doesn't have to modify some global method to add
support of new objet types.
But maybe this is a too specialised use case to be added in boost.
Anyway, if Anthony allows me I will now use his library as the basic
building block of my object factory. Thanks and congratulation for this
very beautiful piece of work.
-- Bien cordialement, Ch. Meessen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk