On Fri, Feb 20, 2015 at 4:23 PM, Gergely Polonkai <gerg...@polonkai.eu>
wrote:

> Hello,
>
> I’m currently implementing a finite state machine in my application using
> Django FSM[1]. In the Usage section of the README the author said that
> “This function may contain side-effects, like updating caches, notifying
> users, etc.”
>
> Opposing this statement, the Symfony PHP framework’s authors say that
> models should never have such side effects.
>
> Thus, I was wondering what is the case with Django in this topic. Should I
> really do such things, like notifying users, in the model’s code?
>

Separation of concerns isn't a Django thing or a Symfony thing - it's a
good software engineering thing.

I can't speak for the creators of Django FSM, but if I was to try an
interpret that statement, I'd say what they were trying to say is "this is
a place from which you can trigger other side effects", not "this is the
best place to put side effect logic".

It's a bit difficult to discuss without a concrete example, but I'd suggest
that the internal logic of your FSM isn't the best place to put complex
logic that touches external services (unless, of course, your FSM is
directly tied to managing that service). However, it *would* be appropriate
for your FSM to take the trigger of a state change, and use that as a
trigger for other system changes.

Put another way -  look at the process for testing your FSM. Will you be
able to test your FSM without a fully functional cache, notification
system, etc? If you're not able to configure your FSM in such a way that a
mock of your notification service can be passed in as a configuration
parameter, then you've probably coupled your FSM and your side effect logic
too closely. However, if you *can* drop in a testing mock as a
configuration item, you've captured the *type* of side effect that you
expect to occur, without tying it to a specific implementation.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849VE%3DJw7DjhTs%3DpRejWtb0q%3Dtab5YeVjbSDQHj%2BkvzuYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to