What to do when an enumeration name collides with a class name?

I have a Pitch enumeration and a Pitch class, and it’s natural for me to be named as such, however this is confusing for the same name. Are there any recommendations as to when an enumeration name comes across a class type?

Example:

public enum Pitch
{
    Fastball,
    Sinker,
    Curveball
}

public class Pitch
{
}
+5
source share
5 answers

Name the enumeration PitchType, PitchKind, PitchMagnitude, PitchQuality, PitchShape, PitchSpeed, PitchStrength, or anything that works best.


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

public abstract class Pitch {}

public class Fastball : Pitch {}

public class Sinker : Pitch {}

public class Curveball : Pitch {}
+7

. - , MusicPlayer.Notes.Pitch Pitch. , .

+3

enum :

public class Pitch
{
    public enum Kind {
        Fastball, 
        Curveball, 
        Sinker
    }
}

:

Pitch.Kind.Fastball
+3

, , , . , joey.

+1
public class Pitch
{
    public enum Enum {
        Fastball, 
        Curveball, 
        Sinker
    }
}

Pitch.Enum.Fastball

0

All Articles