I currently have two (core) classes :
public abstract class BO<TConfig> where TConfig : BOConfigBase
{
protected TConfig Config { get; set; }
internal List<BC> _BCs { get; set; }
public abstract void Init();
public void Process() => _BCs.ForEach(bc => bc.Process());
}
public class BOOne : BO<BOConfigOne>
{
public BOOne(BOConfigOne config)
{
Config = config;
}
public override void Init()
{
_BCs = new List<BC>()
{
BCA.Init(Config),
BCB.Init(Config),
BCC.Init(Config),
BCOneA.Init(Config)
};
}
}
Then the code for my BCs
public abstract class BC
{
protected BOConfigBase Config { get; set; }
public abstract void Process();
}
public class BCA : BC
{
private BCA()
{
}
public static BCA Init(BOConfigBase config)
{
BCA ret = new BCA { Config = config };
return ret;
}
public override void Process()
{
Config.Counter += 1;
}
}
To call this, I will do this :
static void Main()
{
{
var boConfigOne = new BOConfigOne()
{
A = "one",
B = "one",
C = "one",
One = "one"
};
var testBO = new BOOne(boConfigOne);
testBO.Init();
testBO.Process();
Console.WriteLine(
$"A = {boConfigOne.A}, B = {boConfigOne.B}, C = {boConfigOne.C}, One = {boConfigOne.One}, Counter = {boConfigOne.Counter}");
}
{
var boConfigTwo = new BOConfigTwo()
{
A = "two",
B = "two",
C = "two",
Two = "two"
};
var testBOTwo = new BOTwo(boConfigTwo);
testBOTwo.Init();
testBOTwo.Process();
Console.WriteLine(
$"A = {boConfigTwo.A}, B = {boConfigTwo.B}, C = {boConfigTwo.C}, Two = {boConfigTwo.Two}, Counter = {boConfigTwo.Counter}");
}
Console.ReadKey();
}
BO stands for Business Orchestration, and BC for Business Component. A BC would perform a single function, and a BO would contain several of these re-usable BCs.
I would like to change the BO to be able to Init all the BCs generically, something like Init => BCs.Foreach(bc => bc.Init(Config));. The problem is that my BC's Init's are static, hence I can't put it in an interface, and call it on the interface, nor can I put it in the base abstract method, and override it.
Does anyone have a better solution for me?