Should Domain Entities be exposed as Interfaces or as Plain Objects?

后端 未结 4 2009
耶瑟儿~
耶瑟儿~ 2021-01-31 08:14

Should Domain Entities be exposed as Interfaces or as Plain Objects ?

The User Interface :

public interface IUser
{
    string FirstName { get; set; }
           


        
4条回答
  •  情话喂你
    2021-01-31 08:49

    Interfaces are normally considered to be "contracts" and would therefore define behavior. The other major use is for mocking, so that you could provide domain entities that were mock-ups instead of coming from a specific data source (and having dependencies on that source).

    For a simple data transfer object, I can't see a lot of use for defining interfaces, but I'm willing to be proven wrong. I'd go with simple objects for this.

提交回复
热议问题