I use GWT and the Place & Activity mechanism.
It's really sad that Place is a class because my custom place can't extend another class.
When I look at the Place code, I see the following :
public abstract class Place {
/**
* The null place.
*/
public static final Place NOWHERE = new Place() {
};
}
Seeing that, the Place can be an interface. Is there a good reason that GWT team has chosen to make Place an abstract class instead of an interface ?
And to generalize : is there a good reason to create really empty abstract class vs interface ?
An abstract class is used if you want to provide a common, implemented functionality among all the implementations of the component. Abstract classes will allow you to partially implement your class, whereas interfaces would have no implementation for any members whatsoever.
Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes. If you are designing small, concise bits of functionality, use interfaces.
A empty abstract class can be used to group together classes. This is in order to show some intent and to ensure the single responsibility principle that a class should have just one purpose. The example you give uses an interface, not an empty abstract class.
If we want to provide common, implemented functionality among all implementations of our component, use an abstract class. Abstract classes allow us to partially implement our class, whereas interfaces contain no implementation for any members.
In general I would not define an empty abstract class
However, when I would expect some members in the future, I may decide to use abstract class instead of interface
"class" means: this IS A
"interface" means: this SUPPORTS
For "Place" I could really see both with a little intuitive preference for class
Is there a good reason that GWT team has chosen to make Place an abstract class instead of an interface ?
I can't think of one. But to be realistic, complaining about it on SO is not going to achieve anything.
And to generalize : is there a good reason to create really empty abstract class vs interface ?
Hypothetically, you might do this to ensure that there is a single common base class for future anticipated requirements ... or for some other reason.
But generally speaking it is a bad idea ... IMO.
(Of course, things like this often happen for historical reasons; e.g. the abstract
class may have had more members in the past that have since been removed.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With