Re: When would you use abstract classes over interfaces
Daniele Futtorovic wrote:
On 29/07/2008 03:30, sasha allegedly wrote:
I am talking about in practice, when writing production code? I still
think the only good point about abstract classes is ability to add
some implementation.
When would you use abstract classes over interfaces
Hardly ever. If anything, use both.
Abstract classes should be used to allow "borrowing" implementation. In
most situations any public method on an abstract class should be
implementing a method from an interface. All other methods should be
private or protected.
Even if I don't start a design that way, I usually end up refactoring to
have both :-)
First iteration:
public class MyFoo...
Second Iteration
public class AbstractMyFoo...
public class MyFooA extends AbstractMyFoo...
public class MyFooB extends AbstractMyFoo...
Third Iteration:
public interface Foo...
public class AbstractSimpleFoo implements Foo...
public class MyFooA extends AbstractSimpleFoo...
public class MyFooB extends AbstractSimpleFoo...
public class MyFooC extends SomeBar implements Foo...
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>