Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2005-07-10 08:04:19


Good Day,

For the past few years, I have been exposed to both C++ software
development as well as Java software development. I have been lucky
enough to get to use many different frameworks from both languages (ACE
in C++ and countless othes in Java).

Introductions aside, I would like to ask whether a generic object
factory implementation would be best put in a framework or a library.
What I am looking for is something to the effect of the Spring [1]
framework but in C++. With the issues like late/dynamic binding having
many different implementations in many different platforms, the best I
could conceptualize is a static template for different object types.

What I'm looking for is something that will be able to allow me to
forget about reimplementing the static factory every time I need it, and
use a generic template instead. Something that will allow me the
following functionalities:

<code>
// return a reference to a _huge_ statically allocated object,
// too impractical to always instantiate whenever an instance of it
// is needed:
static_factory<Object> ObjectFactory;
...
Object & object1 = ObjectFactory.getObject();
... // later perhaps
Object & object2 = ObjectFactory.getObject();
... // later still
Object & object3 = ObjectFactory.getObject();
</code>

For other cases when I want a different instance returned every time I
need a reference to something new, there's a dynamic_factory --
returning a pointer or reference to an object:

<code>
dynamic_factory<Object> ObjectFactory;
Object instance1 = ObjectFactory.getObject();
std::auto_ptr<Object> instance2 (ObjectFactory.getObject());
</code>

-- Of course, it is assumed that `Object' has a default constructor in
both dynamic_factory and static_factory.

Do you know of anything similar to these already? Otherwise, I would be
most glad to put up a sample implementation soon.

TIA

PS. Perhaps XML definition files may be used to provide object
registration when the factory is used dynamically to load object
definitions from dynamic libraries.

-- 
Dean Michael C. Berris <mikhailberis_at_[hidden]>
GPG Key: 0x08AE6EAC
http://mikhailberis.blogspot.com
Mobile: +63 921 7841815



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk