I'm creating a tool which does a lot of processing on the input fed into the tool and produces output. Here is how i have designed the Tool.
I use "Chain of Responsibility" design principle.
I have classes named Engines that does a Job.
Output of first Engine is the Input to the second Engine. Or it is possible that output of first and second is the Input to the third Engine.
Below is the piece of code that is present in PrincipalEngine.cs(entry point of the Tool from which other Engines are executed):
var contentReadEngineOutput = ExecuteEngine(ContentReadEngine, EngineInput);
var contentParserEngineOutput = ExecuteEngine(ContentParserEngine, contentReadEngineOutput);
var ruleReadEngineOutput = ExecuteEngine(RuleReadEngine, null);
var ruleRunnerEngineOutput = ExecuteEngine(RuleRunnerEngine, contentParserEngineOutput, ruleReadEngineOutput);
ExecuteEngine(ResultPublishEngine, ruleRunnerEngineOutput, contentReadEngineOutput);
private IEngineEntity ExecuteEngine(ILinterEngine engine, params IEngineEntity[] engineEntities)
{
if (engineEntities != null)
engine.InitializeEngine(engineEntities);
return engine.RunEngine();
}
All engines including PrincipalEngine implements the interface ILinterEngine:
public interface ILinterEngine
{
void InitializeEngine(params IEngineEntity[] engineInput);
IEngineEntity RunEngine();
}
Engines are DI injected into PrincipalEngine and ran by providing inputs so as to get the output.
All Engines have an EngineInput type and an EngineOutput type.
For example, below are the engine input/output for Principal Engine:
public interface IPrincipalEngineInput : IEngineInput
{
System.Collections.Generic.List<string> UrlList { get; set; }
}
public interface IPrincipalEngineOutput : IEngineOutput
{
List<RuleViolatingNodeWithURLModel> RuleViolatingNodeWithUrlModelList {
get; set; }
}
And IEngineInput and IEngineOutput implement IEngineEntity.
public interface IEngineInput : IEngineEntity
{
}
public interface IEngineOutput : IEngineEntity
{
}
public interface IEngineEntity
{
}
Now here is my Question:
As evident from the above code, IEngineInput and IEngineOutput has base interface as IEngineEntity. But this interface is empty and has been used so that output of one Engine can be passed as input to the Next Engine in the 'ExecuteEngine' method.
Is this approach correct or is there a better way to do this ?
Aucun commentaire:
Enregistrer un commentaire