Skip to content

Backend Pattern Model

Ferris Tseng edited this page Dec 13, 2019 · 2 revisions

[Pattern] Model

Description

A model contains the attributes and properties that belongs to an object, and methods to help get/set data from the object.

Location

  • app/models

Best Practices

Skinny Model

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

Resources

Examples in Caseflow

Additional Reading

Related Patterns

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
Clone this wiki locally