Enum as Object Value in DDD

Asked

Viewed 772 times

5

After many searches on the internet, I came across many divergent opinions...

In my application, I created the enum EstadoCivil {Casado = 1, Solteiro = 2, Divorciado = 3}. It can be classified as an Object Value, or it is simply an enumerator that will relate to my class?

1 answer

5


Why is Object Value meaning Value Object? If so, an enumeration is a Value Object (has everything he needs to receive this classification), so there is no dichotomy.

If someone thinks an enumeration is not a Value Object that says why. I have not seen anything that indicates that it is not.

Many people will consider the use of enum because this is a mechanism to deal with internal mechanisms of code and not to deal with abstractions of business rules. But there are controversies, so you find dissenting opinions.

Can the range of possible values change? It seems to me that it can, even rarely. If so, do you want to work with an extension of this or reshape the application? You have arguments for both. Some people adopt by default to be able to extend the application without touching anything else. Sounds good, but in practice in various scenarios there are problems in doing so.

In fact there is Microsoft’s own recommendation for use of a normal class instead of an enumeration in certain scenarios (not at all).

Making a class tends to complicate the application. But there are cases that are necessary or useful to solve other issues.

If doing DDD without knowing why you’re doing it, complicating (and DDD tends to complicate the application) without having a clear gain (and much of what people do doesn’t have a clear gain) then you’re doing it wrong, no matter what. If you’re doing something you don’t fully understand (it’s common for people to use things they think they understand but don’t understand) then it’s the wrong tool.

For me it’s not a question of being DDD or not, it’s a matter of necessity.

Additionally I say that in some scenarios there are standardization of this information.

  • Thank you for the information Maniero!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.