I have a project which works on translating languages from one to another and on the UI layer I can only work with one type of Entity class with instantiating it tightly coupled as following;
EnglishTurkish word = new EnglishTurkish()
{
Word = inputText.Text.ToLower(),
Translation = translatedText.Text.ToLower()
};
EnglishTurkishManager englishTurkishManager = new EnglishTurkishManager(new SlEnglishTurkishDal());
Users can choose the source and target language and if the source language is 'English' and the target is 'Turkish' then the code above works fine. But let's assume that the user has chosen 'English' to 'French', then I'd need to instantiate as following;
EglishFrench word = new EglishFrench()
{
Word = inputText.Text.ToLower(),
Translation = translatedText.Text.ToLower()
};
EglishFrenchhManager englishFrenchManager = new EnglishFrenchManager(new SlEnglishFrenchDal());
I can handle instantiating of entity class with Factory design pattern as following;
public class TableInstanceFactory
{
public static IEntity GenerateTableInstance(string tableName)
{
switch (tableName)
{
case "TurkishEnglish":
return new TurkishEnglish();
default:
break;
}
}
}
But this will require so much effort to put all possible table names in the switch statement and somehow I feel like this is not the correct way to do it. Another problem is how to handle the generation of classes with the extension of 'Manager' and 'Dal'(like EglishFrenchhManager and SlEnglishFrenchDal). Is there a better way to do to handle it dynamically?