Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do when an enum name clashes with a class name?

I have an enum Pitch and a class Pitch, both naturally to me should be named as such, however it's confusing to have both with the same name. Are there any guidelines for when an enum's name clashes with a class type?

EXAMPLE:

public enum Pitch
{
    Fastball,
    Sinker,
    Curveball
}

public class Pitch
{
}
like image 566
Rhubarb Avatar asked Dec 04 '11 13:12

Rhubarb


1 Answers

Name the enum PitchType, PitchKind, PitchMagnitude, PitchQuality, PitchShape, PitchSpeed, PitchStrength or whatever fits best.


Another consideration is whether the class design could be improved. Instead of having a PitchType property inside the class Pitch, you could also create a class hierarchy:

public abstract class Pitch {}

public class Fastball : Pitch {}

public class Sinker : Pitch {}

public class Curveball : Pitch {}
like image 84
Olivier Jacot-Descombes Avatar answered Sep 25 '22 21:09

Olivier Jacot-Descombes