What would this enum pattern be called?

enums, java

Solution

I would say that looks a fair bit like the Multiton Pattern. If you do as erikb suggests and use a map instead of looping, I would say it's exactly like the Multiton Pattern.

Problem

I use this technique frequently but I'm not sure what to call it. I call it associative enums. Is that correct? Example: ``` public enum Genders { Male("M"), Female("F"), Transgender("T"), Other("O"), Unknown("U"); private String code; Genders(String code) { this.code = code; } public String getCode() { return code; } public static Genders get(String code) { for (Genders gender : values()) { if (gender.getCode().equalsIgnoreCase(code)) { return gender; } } return null; } } ```

Original source