Factory patterns version 1.2.1 released

February 14, 2009 by Tor Brede Vekterli

Just in time for Valentine's day, the perfect gift for your loved one: shiny factory patterns! Truly it will be a day to remember! So what's new, changed or otherwise mangled to bits this time around?

  • Added support for smart pointer return values (anything with a nested element_type will be recognized). Breaking change: To reduce code horror and increase uniformity, all abstract types must now be specified as a pointer, be it a raw pointer or a smart pointer. This should hopefully help push the concept that the abstract types' result-type represents what is actually returned by the factory.
  • Several throws have been replaced with boost::throw_exception
  • Replaced CreatorPolicy and creator_policy_type in prototype<> with ClonePolicy and clone_policy_type, respectively.
  • Various code tweaks and changes here and there (but nothing else that should break existing code)

To examplify what the breaking change entails, if you have the following piece of code with version < 1.2.1:

typedef abstract_factory<   
  , abstract_monster*(const std::string&, int)
  , abstract_beast
> enemy_factory_t;

it will now have to be written like this in 1.2.1 (note the pointer types):

typedef abstract_factory<   
  , abstract_monster*(const std::string&, int)
  , abstract_beast*
> enemy_factory_t;

but can also be written with (more or less) smart pointer types, particularly if you want more exception safety in your code:

typedef abstract_factory<   
  , boost::shared_ptr<abstract_monster>(const std::string&, int)
  , std::tr1::shared_ptr<abstract_beast>
> enemy_factory_t;

Existing type definitions for concrete factories, as well as calls to create remain unchanged—having to re-specify whether or not the resulting object should be wrapped in a smart pointer here would just introduce redundancy. When passing as individual fields, the full type must be included, though.

For more information about how to deal with this stuff, please refer to the documentation. As always, questions, comments and such are more than welcome.

Posted in:


Theodore on February 15, 2009

Fascinating and informative entry. Well done. You have helped in my future endeavors.

manicure on May 3, 2017

I'm gone to say to my little brother, that he should also visit
this weblog on regular basis to get updated from most up-to-date news update.

Post a comment