Suppose a class allows some kind of configuration that has some well-known default values but also has the option of defining a custom value. For example, suppose you want to let users configure a person's title. They can choose from a set of standard values (Mr., Mrs., Ms., etc.) but they can also specify a custom (Dr.). What is the most elegant way to put this in an API? Some examples in Java:public class Person {  public enum Title {MR, MRS, MS, CUSTOM};  setTitle(Title title, String customTitle);}This one is quite bad because whenever you specify anything else than Title.CUSTOM the second argument is silently ignored.So maybe:public class Person {  public enum Title { MR, MRS, MS, CUSTOM};  setTitle(Title title);  setCustomTitle(String title);}I don't really like this one either, because it's not immediately clear that calling one will overwrite the effects of the other method. Is there a more elegant interface that I'm overlooking?
API design involving standard and custom settings
java;design;api
You could overload the setTitle mthodpublic class Person{    public enum Title { MR, MRS, MS, CUSTOM };    private Title EnumTitle    private String CustomTitle;    public void setTitle(Title title); //Does what you'd expect    public void setTitle(String title)    {        EnumTitle = Title.CUSTOM;        CustomTitle = title;    }    /**     * This does present some problems when returning the value, however.     *     * My first thought to solve this problem is to always expect the      * output of getTitle() to be a string - either the custom title or     * a string representation of the enum value.     */ }