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
の場合も同様で、Path が「.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
ですか? 私のマネージャーが十分に大丈夫かどうか本当にわかりません。これに関するすべての提案を教えてください。