I have a program that receives files from clients and do some operations on files and save them on disk or won’t save them.
For decoupling of jobs, I created an interface named IFileEditor
. Every component that do something on file, should implement this interface:
public interface IFileEditor
{
string Name { get; set; }
byte[] Content { get; set; }
string EditedName { get; set; }
byte[] EditedConent { get; set; }
string ComponentName { get; }
XmlDocument Config { get; set; }
XmlDocument Result { get; set; }
void EditFile(byte[] content);
}
Main method in this interface is EditFile that receives file contents and do operations, and maybe in last save the result on disk. Sample class that I wrote is that create a thumbnail from image that implements this interface:
public class ThumbnailCreator : IFileEditor
{
public string Name { get; set; }
public byte[] Content { get; set; }
public sting EditedName { get; set; }
public byte[] EditedConent { get; set; }
public XmlDocument Config { get; set; }
public XmlDocument Result { get; set; }
public void EditFile(byte[] content)
{
//change the file content and save the thumbnail content in disk
}
}
I may have lots of components like ThumbnailCreator, for example zip content or anything else that do operation on content.
In main program I load every component by reflection. Implementation of loading them is not important, just know that copying ddl of component beside .exe of main program and if dll implements IFileEditor, I add that to list.
Main question is that, main application just receives files and pass them to components, and components do the jobs. If I want to pass the result of one component to another, what should I do?
Remember that components doesn't know each other and main program should not interfere in passing results.
I searched, and I think chain-of-responsibility design pattern will solve my question. I don’t know is that correct? If correct how to implement this? For example one component creates the thumbnail and pass the result to compress the thumbnail.
I wrote this part like this, that every developer can create a component and main program could be extendable.
Thanks for reading this large post. ;)