目前正致力于编写一些可重用的类,并希望在确定在这种情况下使用的正确设计模式方面提供一些帮助。我想将不同(或相同)的对象类型作为输入传递给我的例程,并获得与输出不同的(或在某些情况下,相同的)对象类型。以下是我想象的如果我要以艰难的方式去做这件事。
abstract class IProcess<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >
{
public abstract OutputType_1 Process( InputType_1 input);
public abstract OutputType_2 Process( InputType_2 input);
public abstract OutputType_3 Process( InputType_3 input);
public abstract OutputType_4 Process( InputType_4 input);
public abstract OutputType_5 Process( InputType_5 input);
}
interface IPipeFilter<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >
{
OutputType_1 Execute( InputType_1 input);
OutputType_2 Execute( InputType_2 input);
OutputType_3 Execute( InputType_3 input);
OutputType_4 Process( InputType_4 input);
OutputType_5 Process( InputType_5 input);
}
public class PipeFilter1 <OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >:
IProcess<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >,
IPipeFilter<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >
{
public OutputType_1 Process( InputType_1 input) {//custom logic goes here }
public OutputType_2 Process( InputType_2 input) {//custom logic goes here }
public OutputType_3 Process( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
public OutputType_1 Execute( InputType_1 input) {//custom logic goes here }
public OutputType_2 Execute( InputType_2 input) {//custom logic goes here }
public OutputType_3 Execute( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
}
public class PipeFilter2 <OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >:
IProcess<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >,
IPipeFilter<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >
{
public OutputType_1 Process( InputType_1 input) {//custom logic goes here }
public OutputType_2 Process( InputType_2 input) {//custom logic goes here }
public OutputType_3 Process( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
public OutputType_1 Execute( InputType_1 input) {//custom logic goes here }
public OutputType_2 Execute( InputType_2 input) {//custom logic goes here }
public OutputType_3 Execute( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
}
public class PipeFilter3 <OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >:
IProcess<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >,
IPipeFilter<OutputType_1 , OutputType_2 ,OutputType_3 , OutputType_4 , OutputType_5,InputType_1, InputType_2,InputType_3 ,InputType_4 ,InputType_5 >
{
public OutputType_1 Process( InputType_1 input) {//custom logic goes here }
public OutputType_2 Process( InputType_2 input) {//custom logic goes here }
public OutputType_3 Process( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
public OutputType_1 Execute( InputType_1 input) {//custom logic goes here }
public OutputType_2 Execute( InputType_2 input) {//custom logic goes here }
public OutputType_3 Execute( InputType_3 input) {//custom logic goes here }
public OutputType_4 Process( InputType_4 input) {//custom logic goes here }
public OutputType_5 Process( InputType_5 input) {//custom logic goes here }
}
但是,我想要的是类似于我在下面的内容,但功能与上面的代码大致相同。
public class PipeFilter1 : IProcess<OutputType, InputType>, IPipeFilter<OutputType, InputType>
{
IPipeFilter _root;
public OutputType Process( InputType input) {//custom logic goes here }
public OutputType Execute( InputType input) {
var outfromone = Process(input)
if(_root !=null)
//custom logic goes here
return _root.Execute(outfromone);
}
}
public class PipeFilter2 : IProcess<OutputType, InputType>, IPipeFilter<OutputType, InputType>
{
IPipeFilter _root;
public OutputType Process( InputType input) {//custom logic goes here }
public OutputType Execute( InputType input) {
var output = Process(input)
if(_root !=null)
//custom logic goes here
return _root.Execute(output );
}
}
public class PipeFilter3 : IProcess<OutputType, InputType>, IPipeFilter<OutputType, InputType>
{
IPipeFilter _root;
public OutputType Process( InputType input) {//custom logic goes here }
public OutputType Execute( InputType input) {
var output = Process(input)
if(_root !=null)
//custom logic goes here
return _root.Execute(output );
}
}
请询问是否需要更多信息。我感谢您在解决这个问题上给予我任何帮助。提前致谢。