| Author |
In terms of rework what to choose an interface or abstract class ????
|
simon paul
Greenhorn
Joined: Dec 08, 2003
Posts: 5
|
|
Suppose i have an application w/c may be designed by abstract classes also by interfaces.I would like to go for interfaces for dynamic plug in features.Now if in mid of development lot of changes come in business logics and fn() to be added diff places how to lesses the rework if interface i choose and it gets changed in so many places.Any work around good Disign patterns or alternative approach / go for <<abs>> could any on guide a bit.
|
 |
Michael Ernest
High Plains Drifter
Sheriff
Joined: Oct 25, 2000
Posts: 7292
|
|
Prefer interfaces over abstract classes, that's the best rule I've seen on the subject. In other words, if you are choosing between the two and see no obviouc benefits either way, use an interface; chances are you'll be glad you did. There are two basic reasons for using an abstract class instead of an interface. One is to preserve code in a method implementation which you are quite sure will be used by most, if not all, classes that will extend from this abstract class. Furthermore, you see no likely benefit from reserving inheritance of another class somewhere down the road. Two, an abstract class can contain a sequence of important actions, expressed as method calls in a prescribed order. Interfaces can't do this at all, so if this feature is required -- in applying the Template design pattern, for example -- an interface isn't really an option.
|
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
Actually, there's one pther advantage that abstract classes have over interfaces, specifically when it comes to "rework." I wonder if Simon isn't already aware of this one, having asked the question. If you've got a library API meant for users to implement, as he describes, then if that API is described by an interface, then adding a method to the interface breaks all the user code. The user implementations will be missing a method and calling it will give an AbstractMethodError. If, instead, that library had used an abstract class, then a reasonable default implementation could have been provided. Josh Bloch talks about this in "Effective Java." Anyway, except for this, I agree with Michael: interfaces are generally to be preferred.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
I've been referencing this article all over the place lately: Why Extends Is Evil. Of course the title is an exageration, but the point is good and some of the examples are illuminating.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: In terms of rework what to choose an interface or abstract class ????
|
|
|