C#。我有一个名为FileProcessor
:
class FileProcessor {
public Path {get {return m_sPath;}}
public FileProcessor(string path)
{
m_sPath = path;
}
public virtual Process() {}
protected string m_sath;
}
现在我想创建其他类ExcelProcessor
& PDFProcessor
:
class Excelprocessor: FileProcessor
{
public void ProcessFile()
{
//do different stuff from PDFProcessor
}
}
同样PDFProcessor
,如果路径以“.xlsx”结尾,则文件为 Excel,如果以“.pdf”结尾,则为 pdf。我可以ProcessingManager
上课:
class ProcessingManager
{
public void AddProcessJob(string path)
{
m_list.Add(Path;)
}
public ProcessingManager()
{
m_list = new BlockingQueue();
m_thread = new Thread(ThreadFunc);
m_thread.Start(this);
}
public static void ThreadFunc(var param) //this is a thread func
{
ProcessingManager _this = (ProcessingManager )var;
while(some_condition) {
string fPath= _this.m_list.Dequeue();
if(fPath.EndsWith(".pdf")) {
new PDFProcessor().Process();
}
if(fPath.EndsWith(".xlsx")) {
new ExcelProcessor().Process();
}
}
}
protected BlockingQueue m_list;
protected Thread m_thread;
}
我试图使其尽可能模块化,例如,假设我想添加一个“.doc”处理,我必须在管理器内部进行检查并实现另一个DOCProcessor
. 如果不修改 ,我怎么能做到这一点ProcessingManager
?我真的不知道我的经理是否足够好,请告诉我您对此的所有建议。