-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context class #110
Comments
From my point of view when using dependency injection (which the context object is) the code can usually be used more flexible. Especially when it comes to testing it is much easier with DI then when the code uses singletons internally (which the ROS 1 code relies on heavily). Just a few random references on the topic: |
It's also worth noting that if you do not specify a Context, nodes use a singleton Context. |
thanks, i'm just trying to understand the ros2 code. The Context looked "weird". The links were very helpful. Why is the context not just a service locator (which is apparently also bad(tm) according to stack overflow)? |
Well, the https://en.wikipedia.org/wiki/Service_locator_pattern
However, this is also like a singleton, since the is no "register" step for the information, it is just created if it doesn't already exist. For example, this is how the intra process manager singleton is gotten by the nodes: https://github.com/ros2/rclcpp/blob/release-alpha1/rclcpp/include/rclcpp/node_impl.hpp#L149-L150 Basically nodes which share a Context also share any "singleton" "services" with each other. The more traditional "service locator" pattern would involve either a plugin system (where code is lookup and loaded dynamically) or something like the Windows registry. You could consider the DDS global configuration file a service locator I guess, a la OpenSplice's My opinion is that the "service locator" pattern leads to centralized and hierarchical designs which lead to globals and configuration complexity. The Context pattern, which is used by may systems e.g. OpenGL, allows for composition and decoupling of the configuration for parts of the system. But if you can come up with a rational to organize it differently I'm willing to consider it. |
Dirk's links led to a large amount of reading over the weekend, and there is it my job to close issues, or do you all do that? On Mon, Sep 14, 2015 at 4:16 PM, William Woodall notifications@github.com
|
@BobDean the feedback is welcome! Design patterns are rarely agreed on unanimously. The context seems appropriate here to me, and my intuition is to continue until we have cause to change direction. Please close an issue if your question is resolved. We'll eventually come through and close them with a note to comment if that's in error. |
Signed-off-by: Karsten Knese <karsten@openrobotics.org>
why was the Context pattern chosen over a traditional Singleton pattern?
The text was updated successfully, but these errors were encountered: