Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 接口,其中T是枚举成员。这是糟糕的设计吗?_C#_Generics_Inversion Of Control - Fatal编程技术网

C# 接口,其中T是枚举成员。这是糟糕的设计吗?

C# 接口,其中T是枚举成员。这是糟糕的设计吗?,c#,generics,inversion-of-control,C#,Generics,Inversion Of Control,我正在努力提高我的整体编码技能,同时也在改进我们的航运集成系统的代码库。我希望IshippingProcess实现其中一个ShippingProviders,但我不能使t成为枚举成员,也不希望将其实现为整数。我敢肯定这是一个糟糕的整体设计。我在泛型或IoC方面没有经验 //Interface public interface IShippingProcesses<T> where T : new() { void DispatchOrder(); void Cance

我正在努力提高我的整体编码技能,同时也在改进我们的航运集成系统的代码库。我希望IshippingProcess实现其中一个ShippingProviders,但我不能使t成为枚举成员,也不希望将其实现为整数。我敢肯定这是一个糟糕的整体设计。我在泛型或IoC方面没有经验

//Interface
public interface IShippingProcesses<T> where T : new()
{
    void DispatchOrder();
    void CancelDispatch();
}

//Implementation
class MNGShippingProcesses : IShippingProcesses<>
{
    public void DispatchOrder()
    {
        //implementation
    }

    public void CancelDispatch()
    {
        //implementation
    }
}

//Shipping Companies
public enum ShippingProviders
{
    UPSKargo,
    MNGKargo,
    ArasKargo
}
//接口
公共接口IshippingProcess,其中T:new()
{
作废调度单();
void CancelDispatch();
}
//实施
类MNGShippingProcesses:IShippingProcesses
{
公共无效调度命令()
{
//实施
}
公共调度()
{
//实施
}
}
//航运公司
公共枚举ShippingProviders
{
厄普斯卡戈,
MNGKargo,
阿拉斯卡戈
}

不清楚泛型在这里为什么有用。只需如下定义您的界面:

public interface IShippingProcesses
{
    void DispatchOrder();
    void CancelDispatch();
}
相应地实现接口

如果您需要选择基于运行时
enum
的实现,比如
ShippingProviders
,那么有很多选项可供选择。有关各种设计的详细说明,包括权衡的讨论,请参阅以下文章:


不太清楚你想要实现什么。已经很奇怪的是,
T
从未在
ishipingprocesses
中实际使用过,请检查此项,此处不需要泛型。如果您需要有关泛型的更多信息,可以从