dimanche 14 mars 2021

How to use factory design pattern for language pairs?

I'm designing a custom app for learning words. In my app's UI, there are two combo boxes that allow the user to choose target and destination languages. These combo boxes' item source is an enum called 'Language' as following;

public enum Language
{
    English,
    Turkish,
    German,
    Spanish,
    French
}

sourceLanguageCombo.ItemsSource = Enum.GetValues(typeof(Language)).Cast<Language>();
targetLanguageCombo.ItemsSource = Enum.GetValues(typeof(Language)).Cast<Language>();

After the user chooses language pair, then I need to create a table name according to these enums using a factory class called 'LanguageTableFactory' as following;

public static class LanguageTableFactory
{
    public static GenerateLanguageModel(Language sourceLanguage, Language targetLanguage)
    {

    }
}

For example, the user chooses English-German as language pair, then after passing this pair as a parameter, I want my factory class to generate the 'EnglishGermanWords' string as output for me to use it later to access the corresponding table name from the database. I know how to do this in a hard-coded way but it will take too much effort and time to write all viable combinations into this factory class. Is there a more generic or creative way to create this table name from enum parameters?

Aucun commentaire:

Enregistrer un commentaire