Comparison
Active recordvsRow data gateway
Active record
the object has a save method on it, so the thing that models an order also knows the table it lives in.
An object that wraps a row and carries both the domain logic and its own persistence — `user.save()`. It is fast to write and reads well when the object model and the table are close to a one-to-one match, which is most CRUD applications. The bill arrives when they diverge: the domain object cannot be tested without a database, cannot be modelled independently of the schema, and quietly acquires a second responsibility it can never give back.
Full entry →Row data gateway
each object is exactly one row, with a getter per column and nothing that knows anything about the business.
An object that represents a single record, holding its fields and the methods to load and save it, with no domain logic. It is active record minus the behaviour, and it exists as a name mostly to make that comparison possible. Its usefulness today is in explaining what an ORM-generated entity actually is when nobody has added methods to it.
Full entry →