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 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
  • 218,019
  • 46
  • 414
  • 706