When designing an application's back-end you will often need to abstract the systems that do things from the systems that actually do them.
There are elements of this in the CQRS and PubSub design patterns.
By way of example:
- A new user submits a registration form
- Your application receives that data and pushes out a message saying
“hey i have some new user data, please do something with this”
- A listener / handler / service grabs the data and processes it
(please let me know if that makes no sense)
In my applications I would usually:
- Fire a new Event that a Listener is set up to process
Event::fire('user.new', $data)
- Create a new Command with the data, which is bound to a CommandHandler
new NewUserCommand($data)
- Call a method in a Service and pass in the data
UserService::newUser($data)
While these are nearly exactly the same, I am just wondering - how do you go about deciding which one to use when you are creating the architecture of your applications?