Should I ever use Enums as discriminators?

前端 未结 2 1441
死守一世寂寞
死守一世寂寞 2021-01-13 10:18

When do Enumerations break down?


To support a new feature in an existing system, I was just considering implementing some form of discriminator to an entity ta

相关标签:
2条回答
  • 2021-01-13 10:47

    Those Enumeration Classes look neat, I've often looked jealously at Java's enums.

    I think the usual rules apply: do the Simplest Thing That Could Possibly Work. If you find yourself with more than one switch on the enum, then that's a smell, and time to consider the pattern you've found.

    Otherwise, why burden yourself with something you don't need?

    0 讨论(0)
  • 2021-01-13 11:08

    Today enums are evil, tomorrow OOP might be evil and AOP will be fine.

    Just use the right tool for the job. Remember, Keep It Simple...

    If the enum is just for the sake of telling the type of an object - don't bother, use it.

    If it has some business logic in it, then it is probably another class.

    0 讨论(0)
提交回复
热议问题