Why does active record pattern not work with rich domain models? Why does active record pattern not work with rich domain models? php php

Why does active record pattern not work with rich domain models?


What he's trying to say is that more complex domain models are usually more than just "data from a table". These more complex models Fowler is talking about are models that get data from different tables, views or maybe even other sources.

The Active Record pattern is not very suitable for this purpose, and the DataMapper pattern combined with just model classes (containing just the business logic and do not communicate with the data access layer) is probably more suitable in situations like these.

The Active Record pattern fails here, because it maps more or less directly to a table in the database.

I don't know the exact pattern definition, so please correct me if i'm wrong.


No, I think he is talking about the domain logic. With active record the object carries both data and behavior. So that is a one-to-one match. If you start separating data/behaviour, like in the Data Mapper pattern, it becomes one-to-many. I have the impression that you sometimes really have to read that book like academic nonsense to understand what he means. :-)