-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Model
Ferris Tseng edited this page Dec 13, 2019
·
2 revisions
A model contains the attributes and properties that belongs to an object, and methods to help get/set data from the object.
app/models
Move functionality outside of the models, and keep them lightweight for readability. 1
Models tend to easily get fat, some of the workflows grow extensively. Anytime our model gets really big it should be a red light that indicates that we're probably doing something wrong. Keep it slim! 2
Model would have to know about many things it shouldn't be concerned about. We could, for one, want to notify the user via email that his application was accepted/rejected. Maybe some of the events can be omitted only by admin user? Sure, we could do all of this in the same class but there's a better way to do this. 2
- 1: https://medium.com/marmolabs/skinny-models-skinny-controllers-fat-services-e04cfe2d6ae
- 2: https://www.monterail.com/blog/2017/decoupling-models-workflow
- https://medium.com/marmolabs/skinny-models-skinny-controllers-fat-services-e04cfe2d6ae
Pattern | Description |
---|---|
Concern | Sharing code between models |
Decorator | Separating display logic |
Delegation | Calling code for related objects |
Factory | Faking models for tests |
Generator | Faking models for tests |
Migration | Related database schema change |
Repository | Interactions between multiple models |
Serializer | Formatting data for the frontend |
Service | Grouping related business logic |
Workflow | Grouping related business logic |