When building a full-stack app, I find it frustrating to define basically 3 nearly identical types:
- What I consider the main struct: defining the logic of the type disregarding any GUI/DB needs. This is the struct you’d define normally. This struct would contain only the most basic fields needed to define it “in real life” (e.g. a
password). Methods associated with it would only deal with actions that have to do with what it actually is.
- The back-end struct: same as in #1 but for the database, with the obligatory
idand maybe public
idfor associations with other entities. Methods with this one would be CRUD.
- The front-end struct: Again, same as #1 but for the GUI. User-facing with some additional checks and validations.
How do you cope with this duplicity (triplicity)? It isn’t the end of the world, but I keep thinking that if and when I’ll want to change some property of one of the types (probably #1) I’ll need to manually propagate (read replicate) the change to all 3 (nearly identical) implementations.
The specific tools I’m using right now are Genie, Stipple, SQLite, SearchLightMySQL (and later postgres).
Thanks for any insight!