Feature #517
Necessity of Factory?
Status: | Resolved | Start date: | 08/20/2011 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | J. Moringen | % Done: | 100% | |
Category: | - | |||
Target version: | - |
Description
Originally reported by Robert Haschke:
looking at the RSB examples, I'm wondering, why it is necessary to explicitly instantiate and use the
rsb::Factory
? I guess, that's a singleton. As a user I find it quite annoying to write two code lines to instantiate a listener or informer somewhere. Hence a appreciate the introduction of convenience methods which do this, e.g.:> template <class T> > Informer<T>::Ptr createInformer (...) { > return rsb::Factory::getInstance().createInformer<T> (...); > } >
What do you think?
Associated revisions
fixes #517
- src/CMakeLists.txt: added files src/rsb/CreateFunctions.{h,cpp}
- src/rsb/CreateFunctions.{h,cpp}: new files; contain convenience
functions for creating participants like listeners and informers
without using the RSB factory explicitly
History
#1 Updated by J. Wienke over 12 years ago
This increases the coupling and reduces the possibility of producing testable code. If you have a factory instance, that can be passed around (which means preventing to use getInstance all the time), you can configure your user objects with a different factory instance for unit testing. With direct function calls this is not possible.
#2 Updated by J. Moringen over 12 years ago
- Status changed from New to In Progress
- Assignee set to J. Moringen
- % Done changed from 0 to 30
- Initially, the convenience functions are implemented as proposed by Robert
- A
Factory
interface is extracted to allow for alternative factory implementations - The global
Factory
instance is made exchangable viaSingleton<Factory>::setInstance()
or something similar - Using thread-local storage or similar mechanisms,
Factory
instances are made locally exchangable, i.e.{ WithScopedFactory bla(new MyMockFactory()); // do something with Factory::getInstance() }
#3 Updated by J. Moringen over 12 years ago
- Status changed from In Progress to Resolved
- % Done changed from 30 to 100
Applied in changeset r2515.