Why use universal and neon options for functions?

I study the code of some different libraries and notice that some of them will provide equivalent general and non-general functions in one class.

One example is the IServiceLocator interface of a common project maintenance locator :

public interface IServiceLocator
{
    object GetInstance(Type serviceType);
    object GetInstance(Type serviceType, string key);
    IEnumerable<object> GetAllInstances(Type serviceType);

    TService GetInstance<TService>();
    TService GetInstance<TService>(string key);
    IEnumerable<TService> GetAllInstances<TService>();

}

The impression I get is that it maximizes availability, possibly from COM. In the absence of these problems, this seems like redundant code. Is there something I am missing?

+3
source share
3 answers

, , , , , , , , .

, . , , , .

+2

, , .

, , , .

, .

+6

The reason is that non-Generic will use the implied generics, checking its type so you don't have to mention the type.

0
source

Source: https://habr.com/ru/post/1772295/


All Articles