I want to do this in the right way to learn
I have a few classes which have only one method. For example:
public class RedColorText
{
public void AddRedColorText(string text)
{
//something here
}
}
public class WhiteColorText
{
public void AddWhiteColorText(string text)
{
//something here
}
}
Normally I could just create instance of each one of them based on the method I want to use but what if I got requirement to use only one class and call methods based on condition? Can I do this like below using constructor and switch? Or should I use something else like interfaces etc?
public class ColorText
{
public ColorText(enum condition, string text)
{
switch(condition)
{
case 1:
new RedColorText().AddRedColorText(text);
break;
case 2:
new WhiteColorText().AddWhiteColorText(text);
break;
}
}
}
addText()
.