Since Erlang isnt really object oriented, there is no real singleton class but i guess a process which is registered can be used as one.
Is it good practice to use registered processes for that inside an application to make the access easier? Disadvantage i see that for example that you cannot run more than one instance of such an application inside one node.
Take as example a gui application with a process managing the events and some other responsible for the sound.
Would it be good practise to make those 2 "singleton" as registered processes and call them like sound:play(file_name)
instead of storing the pid and doing sound:play(Pid, file_name)
?
It is fairly common to use a gen_server under a registered name to do exactly this. You can export functions from that same module which simply do a gen_server:call against the named process in question.
(Arguably, Erlang is more "really" OO than what you're probably used to. But that's not what this question is about.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With