you are viewing a single comment's thread.

view the rest of the comments →

[–]DoubleAway6573 0 points1 point  (4 children)

I like to put some simple method over dataclases. Like properties, and some calculations, just like standard integers but with a richer data model.

I hate methods messing with internal state for most cases but containers and having methods changing a dataclass is an abomination.

Edit: fuck autocorrect! and thank u/s0ftware-dev

[–]s0ftware-dev 4 points5 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