【发布时间】:2019-04-27 16:33:12
【问题描述】:
我有一个 Windows 服务应用程序,它读取一些文件并进行一些修改并上传到 Web API。
在这里我尽可能地遵循单一责任原则。
在这个应用程序中,我有 3 个类来读取文件的内容、应用业务逻辑并将修改后的内容上传到服务器。
class GetFileContent {
// in here there is a method to return the file content
}
class ApplyBusinessLogic {
// in here there is a method to get that file content as param and apply business logic
}
class UploadContent {
// get the modified content and upload it
}
现在我的问题是,如果我添加了一个新类 DoMyActions 并创建上述类的对象并调用执行这些任务的方法,这是否违反了单一责任原则?为了弄清楚我的问题,我正在尝试执行以下操作。
class DoMyAction {
GetFileContent content = new GetFileContent();
// call the method in above class and get the content
ApplyBusinessLogic doMyThing = new ApplyBusinessLogic();
// do my stuff using that file content
UploadContent uploader = new UploadContent();
// upload the content
}
有没有更好的方法?
如果我一直想使用DoMyAction 类如何遵循单一职责原则?
【问题讨论】:
标签: c# .net oop solid-principles single-responsibility-principle