Skip to content

The same data shape in several layers (DTO, model, entity) ​

Code that already exists: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. What lessloc does: copy catches identical type bodies.

What makes the same data shape in several layers (DTO, model, entity) a bad practice? ​

The standard that calls it a bad practice: DRY.

What does lessloc do about the same data shape in several layers (DTO, model, entity)? ​

copy catches identical type bodies.

  • copy (tier 1): A block of dupLines code lines that also exists elsewhere, or a function with the same body as another under other names.

Examples ​

Caught as copy:

python
from dataclasses import dataclass


@dataclass
class UserDTO:
    id: int
    name: str
    email: str
    active: bool
    plan: str
    seats: int
    created: str
    region: str


@dataclass
class UserRecord:
    id: int
    name: str
    email: str
    active: bool
    plan: str
    seats: int
    created: str
    region: str

Written well:

python
from dataclasses import dataclass


@dataclass
class Account:
    owner: str
    limit: int

The other patterns in Code that already exists:

Released under the Apache-2.0 license. · llms.txt