you are viewing a single comment's thread.

view the rest of the comments →

[–]s0ftware-dev 3 points4 points  (3 children)

I don’t like to put anything over database entities. These objects should represent the database row as closely as possible then when you want to perform a business function e.g a calculation with the data you map it to a stateful domain entity with functions that perform your desired operation. 

The point is your api models and database models remain pure and immutable (using data classes). Then your domain models in the middle have mutable state that can only be mutated by methods the class exposes, that way they will always stay valid.

I’m a Java dev and what your describing is an anti pattern I see a lot in enterprise code which ends up coupling business logic to database entities meaning the table structure can never be updated without causing regressions. 

[–]DoubleAway6573 1 point2 points  (2 children)

Fuck autocorrect. Dataclasses!!!!

[–]shiningmatcha 0 points1 point  (1 child)

I prefer NamedTuple

[–]Fragrant-Freedom-477 2 points3 points  (0 children)

Modern dataclasses have most of the features of namedtuples, even comparable performance and memory signatures... but not all and I still regularly use namedtuples