Skip to content

Signal/event/observer pattern #2787

Answered by SolarLune
musjj asked this question in Q&A
Sep 25, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

You could do this with message passing - a message can be anything and fulfill a certain interface. You register listeners with some global object, and then send messages to those registered listeners. Those listeners can be any kind of object.

Here's a repo that does that: https://github.com/SolarLune/messages

You could also just do this with interfaces directly, as objects can be checked to see if they implement an interface, which would indicate they subscribe to the desired message type.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@musjj
Comment options

Answer selected by musjj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants