If you want to change your business work flow on air you can use dependency injection in your programs. You can decide which class to use for your customers requirement dynamically via dependency injection method. Here is a sample code for dependency injection. 2 payment methods and 2 record saving methods implemented.
interface IPay
{
void Pay(string amount);
}
class CreaditCardPay : IPay
{
public void Pay(string amount)
{
Console.WriteLine("CreaditCardPay:" + amount);
}
}
class CashPay : IPay
{
public void Pay(string amount)
{
Console.WriteLine("CashPay:" + amount);
}
}
--------------------------------------------------------------
interface ISave
{
void Save(string amount);
}
class FileSave : ISave
{
public void Save(string Message)
{
Console.WriteLine("FileSave:" + Message);
}
}
class DBSave : ISave
{
public void Save(string Message)
{
Console.WriteLine("DBSave:" + Message);
}
}
------------------------------------------------------------------------
<appSettings>
--------------------------------------------------------------------------
class PrepareClass
{
public IPay createPayer()
{
IPay payer = null;
if (ConfigurationSettings.AppSettings["pay"].Equals("CreaditCard"))
payer = new CreaditCardPay();
else
payer = new CashPay();
return payer;
}
public ISave createSaver()
{
ISave saver = null;
if (ConfigurationSettings.AppSettings["log"].Equals("DB"))
saver = new DBSave();
else
saver = new FileSave();
return saver;
}
}
-------------------------------------------------------------------
class Program
{
static void Main(string[] args)
{
PrepareClass p = new PrepareClass();
ISave lg = p.createSaver();
lg.Save("100$");
IPay m = p.createPayer();
m.Pay("100$");
}
}