Accurate Models

A fundamental concept to improve your code

July 18, 2020

programming

Enjoying my writing? Sign up to hear about future posts!

2 min read

Most of writing good software is accurate modeling.

Front end

Start with the slice of your software that is your primary differentiator. For most business software, this will be your user interface. What are the UI primitives on the screen? Cards? Lists? Is your data nested? Your front end data models should accurately represent your UI.

Database/back end

Your database should be modeled after how your customers see the business concepts your software solves. What do your customers talk about? Invoices? Prices? Customers? Invoices? Products? Line items? Your database models should match the model in your customers’ head as closely as possible.

Integration

The first thing your front end should do when it receives your database models is transform them to the front end model. Typically this is done through a factory function or constructor. This way your front end programmers can work in the mental model of the UI without having to translate back and forth for every interaction in your front end.

You should then create another set of factory functions or constructors that transform your data from the front end model back to the database or API model that you can pipe your data through on the way back to your backend.

A diagram of backend and front end model integration

Refactor and update

Sometimes things change. It is critical to refactor your models when this happens. Working with an out of date model adds significant overhead to every single interaction with the code that uses it. This overhead compounds over time and adds up to be an extreme cost. Anytime you see code that works around an inaccurate model, schedule work to update it. In general, the up front work will save tons of overhead longer term.

Enjoying my writing? Sign up to hear about future posts!