Short answer: No.
Long answer: There's a trade-off between using a class and an interface. Interface implementations can be swapped at runtime. That's nice because it's flexible - but it also means someone can code up a bad IFoo
and pass it to one of your functions that otherwise works fine. With a concrete (and sealed
/final
) Foo
there's only one implementation, so if you get it right, it always works.
Another drawback of interfaces is that they can't inspect the implementation details of other members of that interface. Foo
methods can inspect the private variables of other Foo
s, but IFoo
s can only look at the interface of other IFoo
s. This can limit certain optimizations, so if there's only one implementation of an interface it can hurt you without providing any benefits.
Unfortunately mainstream OOP languages don't provide a way to swap class implementations. Ideally you'd be able to have multiple Foo
implementations and pick one of them at compile time. However, with an IDE it's not hard to extract an interface out of a class after the fact.
If you don't need to juggle multiple kinds of Foo
s in the same program there's no need to add an extra layer of indirection with an interface. Even if you do need multiple kinds of Foo
s in the same program, you don't necessarily need an interface. You can have an abstract base class with a private constructor and implement a finite number of types of Foo
s as static final
inner subclasses. See also How do you encode Algebraic Data Types in a C or Java-like Language.
Interfaces really shine when you don't want to limit the number of possible implementations usable at runtime at all.
EDIT: For a more thorough explanation of the trade-offs involved, see On Understanding Data Abstraction, Revisited.