Not noticing new objects or resources other than those that already exist in the domain is a common mistake. Because of it, we start to spread the entire behavior of an application across three or four models — God classes.
Let's say we have a blog service where administrators approve posts. Usually we tend to add approve and disapprove actions to the PostsController
:
PATCH /posts/1/approve
DELETE /posts/2/disapprove
PostsController
becomes huge and unmanageable. A "refactor the PostsController" task is added to the tracker.
But if you look closely and ask yourself "should the PostsController
receive approve or disapprove? If not, then who?", you may notice a new object and resource Approval
:
POST /posts/1/approval
DELETE /posts/2/approval
PostsController
remains the same, ApprovalContoller
turns out to be small and focused on a single task.
tl;dr Don't try to fit everything into existing objects: models, controllers. Look for new objects and resources
Top comments (0)