Im目前正在设计一个处理不同类型档案的处理系统。 我确定了以下接口:
public interface IFileProcessor
{
bool ProcessFile(string fileContents)
}
目的是建立若干具体执行机制,处理不同类型的档案。 管制人员班负责:
- Watching a folder for a newly added file
- Reading the file contents
- Obtaining a collection of these IFileProcessor concrete implementations
- One by one call the ProcessFile() on each component, passing the file contents
- If a component cannot process the file it returns false, otherwise it will process the contents and return true
- If no IFileProcessor implementation can process the file it is moved by the controller to a UnProcessed folder
- If a component successfully processes the file it is moved to the Processed folder
- If an exception is thrown by a component it is moved to a Failed folder
我正在创立一个化粪池,它将首先检查它是否能够根据类型(即csv)处理档案,然后进行一些最高一级的验证(即核对档案负责人)。 如果这些检查没有例外,就会把整个档案视为无效。
然而,一旦最高一级验证成功,该构成部分将处理档案中的每一行。 从此以后,单个项目无法进行处理(即验证)是可以接受的,其余工作将继续进行。
This is where the problem lies, I am wondering if its best to log that validation errors have occurred and then throw an exception at the end of the process, or to change the ProcessFile() signature to return an enum (one of Processed, UnProcessed, ProcessedWithErrors)?
From what I have read it seems that exceptions are the preferred route over status codes, however in this particular circumstance where a process can continue it seems wrong to use an artificial exception at the end to state the process did not complete 100%.
我真正关心各国人民对此的想法。