Replace Type Code with Class

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
 
If a class has a numeric type code that does not effect its behaviour.
 
If a class has a numeric type code that does not effect its behaviour.
  
Line 10: Line 9:
  
 
[[Enum idiom]]
 
[[Enum idiom]]
 +
[[Beware value switches]]

Revision as of 00:13, 7 October 2008

If a class has a numeric type code that does not effect its behaviour.

Replace the number with a new class.

Whether or not it was considered good style in C programming (and any of its descendants), it was common to use symbolic constants or enums to represent a range of values. The underlying mechanism for this to use integers for the symbol values, because of this the compiler can offer no help in protecting against the assignment of illegal values.

See Also

Enum idiom Beware value switches

Personal tools