OO best practice regarding returning a less / more specific interface when returning an interface

This title is a bit complicated ... When I write an interface, is it better to use the most specific interface at all, or the least?

For example, suppose that

interface List2<T> extends List<T>
{
    List<T> getRange(int startIndex, int endIndex);
}

It would be better to change it to

interface List2<T> extends List<T>
{
    List2<T> getRange(int startIndex, int endIndex);
}

so that callers can call getRangeby their result, but still match List is polymorphic?

+5
source share
1 answer

(, ), , . , , , , .

API, , , .

+2

All Articles