Choosing between immutable objects and structs for value objects

后端 未结 11 1578
鱼传尺愫
鱼传尺愫 2020-12-13 15:07

How do you choose between implementing a value object (the canonical example being an address) as an immutable object or a struct?

Are there performance, semantic or

11条回答
  •  青春惊慌失措
    2020-12-13 15:54

    I actually don't recommend using .NET structs for Value Object implementation. There're two reasons:

    • Structs don't support inheritance
    • ORMs don't handle mapping to structs well

    Here I describe this topic in detail: Value Objects explained

提交回复
热议问题