Is using one-to-one interfaces with domain entities a good or bad practice? Why?

后端 未结 6 1139
梦谈多话
梦谈多话 2021-02-01 17:16

One thing I see in some DDD enterprise apps that I work on, is the use of interfaces that are identical to the domain entities, with a one-to-one mapping of properties and funct

6条回答
  •  孤街浪徒
    2021-02-01 17:49

    It's a bad practice as described, but...

    There's no specific reason that your interfaces need to be different than your domain entities; sometimes it really is the right mapping. But it's suspicious that it's always the case. The point of concern there is a question of whether or not the interfaces were truly designed, or whether they were just thrown into place out of lack of time / laziness.

    To use your example, the IAccount interface you describe exposes getters and setters on the Account object; it seems a little odd and unlikely that everything that uses an Account will have a need to set the balance on the account, and that that implied permission is specified at that level of interface. Is there no place in your system where you want to merely check but not set the Account balance?

提交回复
热议问题