-
Notifications
You must be signed in to change notification settings - Fork 775
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
[20543] Examples refactor: Hello World #4547
Conversation
48f5bad
to
bb375a4
Compare
c366a69
to
6f2a1e0
Compare
7af5a31
to
d73f963
Compare
6f2a1e0
to
c6e0741
Compare
d73f963
to
2dc171a
Compare
3cd6aa0
to
30317aa
Compare
813cb7d
to
fe33b04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're definitely getting there! I like the idea of the classes not having any static members.
Now, I have a "crazy" idea to simplify the main and to also group some of the subscribers' code. Right now, all three entities have similar public API:
- A ctor
- A
run
member function with no args - A
stop
member function with no args
We can do some hierarchy of classes:
classDiagram
class Entity {
+run() void
+stop() void
+create_entity(const hello_world_config& config)$ std::shared_ptr~Entity~
}
Entity <|-- Publisher
Entity <|-- AbstractSubscriber : Optional grouping of subscriber code
AbstractSubscriber <|-- Subscriber
AbstractSubscriber <|-- WaitSubscriber
Entity ..> Publisher : creates
Entity ..> Subscriber : creates
Entity ..> WaitSubscriber : creates
We would have a base class for the entities which can also act as a factory of the specializations via an static method. This way you don't need all those pointers, just the one, nor do you need any switches. You'd just create the entity passing the config and then spawn the thread to run it's run method. Since the entity is a shared_ptr
, you wouldn't need to delete it either. You can see a PoC here.
(NIT) Apart from the internally agreed things I would call the creation method (or global free function) |
b2a2839
to
5064ab8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is turning out nicely, great job! 🤖
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: JesusPoderoso <[email protected]>
fbafb51
to
416fce2
Compare
Description
This PR should be merge right after:
This PR is the first of a suite of PR which would make a refactor in the repository examples.
It is intended to apply to most of the examples, by making them homogeneous, more understandable, and more specific to the case they were meant to be.
In this hello world example, the key changes are:
The following changes apply to this and the remain examples:
Contributor Checklist
versions.md
file (if applicable).Reviewer Checklist