0

I'm trying to improve my overall coding skills and also improve our codebase for the shipping integration system. I want IShippingProcesses to implement one of the ShippingProviders but I can't make the T an Enum member, and I don't want to implement it as an integer. I'm pretty sure this is bad design overall. I'm not experienced in generic types or the 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
}
  • 1
    Not really clear what you want to achieve. It already is strange that `T` is never actually used in `IShippingProcesses` – H H Jul 26 '19 at 09:14
  • Check this https://stackoverflow.com/a/8086788/6877477 – Anton Kahwaji Jul 26 '19 at 09:14
  • no need of generics here. If you need more info about generics, you may start from [docs](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/) – vasily.sib Jul 26 '19 at 09:16

1 Answers1

1

It's unclear why generics would be useful here. Just define your interface like this:

public interface IShippingProcesses
{
    void DispatchOrder();
    void CancelDispatch();
}

Implement the interface accordingly.

If you need to select an implementation based on a run-time enum like ShippingProviders, there's quite a few options for that. Please refer to these articles for detailed description of various designs, including discussion of trade-offs:

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736