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

后端 未结 4 2008
耶瑟儿~
耶瑟儿~ 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:58

    Plain objects, unless there's a common interface for an implementation that can change. That's what interfaces are for. Value classes like Money or Address don't fall into that category.

    Your example interface has no behavior whatsoever beyond getter/setter. That's not what interfaces are for.

提交回复
热议问题