Service Classes
Learn the principles you can follow to make service classes better.
What are services?
Services are the classes containing domain and application logic. Every service provides an API to trigger some actions, be it something small like formatting data or something big like creating orders.
Services are also notable because they don’t care what calls them. Each service encapsulates an operation that can be run by a controller, console command, test, or another service.
How to make good services
We want to make good services. But, to achieve this, we first need to understand what a good service means. A good service is:
- Easy to use.
- Easy to test.
- Easy to modify when requirements change.
Another distinctive feature of good service is predictability. We should be able to tell what a service does just by looking at its external API and without knowing how the service works inside.
It should be true predictability. Sometimes the service API looks simple but doesn’t show the whole picture. The service might also do something ...