Empty abstract class / interface bad design badge?

I have the following class structure:

enter image description here

The fact is that each request has nothing in common, as when processing requests that I execute typeof/ cast. The reason for having an empty root class is the restriction at compile time which classes you can pass to the request processing method:

void ProcessRequest(Request request)

Is this design incorrect? It seems strange to me to have an empty root class / interface.

+4
source share
3 answers

. , . , "OO-way" inheretance - , , . , void Process(Request request) , , /else .

public class RequestA
{
}

public class RequestB
{
}

public class RequestC
{
}

public class RequestProcesser :
    IProcessRequest<RequestA>,
    IProcessRequest<RequestB>,
    IProcessRequest<RequestC>
{
    public void Process<RequestA>(RequestA request)
    {
    }

    public void Process<RequestB>(RequestB request)
    {
    }

    public void Process<RequestC>(RequestC request)
    {
    }
}

public interface IProcessRequest<TRequest>
{
    void Process<TRequest>(TRequest request);
}
+2

"" " , .

+1

.

. , , .

, , object, . , .

+1
source

All Articles