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

后端 未结 2 1145
半阙折子戏
半阙折子戏 2021-02-08 05:31

I\'m reading the architectural patterns chapter of POEAA, and Fowler says that \"As the domain logic gets more complicated and you begin moving toward a rich Domain Model (116),

相关标签:
2条回答
  • 2021-02-08 05:45

    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. :-)

    0 讨论(0)
  • 2021-02-08 05:59

    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.

    0 讨论(0)
提交回复
热议问题