Backend Pattern Model - department-of-veterans-affairs/caseflow GitHub Wiki

[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
⚠️ **GitHub.com Fallback** ⚠️