6 replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
source | link

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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos as static final inner subclasses. See also How do you encode Algebraic Data Types in a C or Java-like LanguageHow 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.

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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

5 added note on sealed/final
source | link

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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

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 concreteFoo 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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

4 Added paper discussing ADTs vs objects
source | link

Short answer: No.

Long answer: There's a trade-off between using a concrete typeclass 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 concreteFoo 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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos as static final inner subclasses. See also How do you encode Algebraic Data Types in C#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.

Short answer: No.

Long answer: There's a trade-off between using a concrete type 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 concreteFoo 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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos as static final inner subclasses. See also How do you encode Algebraic Data Types in C#.

Interfaces really shine when you don't want to limit the number of possible implementations usable at runtime at all.

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 concreteFoo 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 Foos, but IFoos can only look at the interface of other IFoos. 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 Foos 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 Foos 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 Foos 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.

3 Added note on finite number of subclasses
source | link
2 added 102 characters in body
source | link
1
source | link