Skip to main content
added 550 characters in body
Source Link
JacquesB
  • 62.4k
  • 21
  • 137
  • 190

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from DeclarationType, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

Edit: In your "real-life scenario" it seems there are multiple places where behavior is selected depending on the value of the enum. This is really an antipattern, since you are using switch + enum as a "poor mans polymorphism". Just turn the enum value into distinct classes encapsulating the declaration-specific behavor, and your code will be much cleaner

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from DeclarationType, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from DeclarationType, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

Edit: In your "real-life scenario" it seems there are multiple places where behavior is selected depending on the value of the enum. This is really an antipattern, since you are using switch + enum as a "poor mans polymorphism". Just turn the enum value into distinct classes encapsulating the declaration-specific behavor, and your code will be much cleaner

added 4 characters in body
Source Link
JacquesB
  • 62.4k
  • 21
  • 137
  • 190

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from DeclarationDeclarationType, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from Declaration, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from DeclarationType, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.

Source Link
JacquesB
  • 62.4k
  • 21
  • 137
  • 190

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused.

If I understand correctly, you have a hierarchical classification of declarations. This is far to much information to encode in a single enum. But there is an obvious alternative: Use classes and inheritance! So Member inherits from Declaration, Property inherits from Member and so on.

Enums are appropriate in some particular circumstances: If a value is always one of a limited number of options, or if it is any combination of a limited number of options (flags). Any information which is more complex or structured than this should be represented using objects.