[erlang-questions] Design pattern: single responsibility
Richard A. O'Keefe
ok@REDACTED
Fri Mar 6 00:55:35 CET 2015
We've had a thread about the use or otherwise of design patterns in Erlang.
I've also had some mail that had me thinking about this.
One idea which already has a name is "Single Responsibility".
The Wikipedia article http://en.wikipedia.org/wiki/Single_responsibility_principle
says it's about classes, but really it's nothing but cohesiveness
by another name.
In the context of Erlang,
the idea is that each process should do one job.
Advantages:
Suppose a process has two jobs, A and B.
And something about working on A makes it crash.
Now nobody is doing job B.
If we have two processes, they can execute on
different cores.
Disadvantages:
If jobs A and B are coupled somehow, there will have
to be communication between the processes working on
them that there wouldn't be in a single process.
Example:
Separating logging from working.
More information about the erlang-questions
mailing list