In Driver
, you have various abstract method declarations, each of which takes in interfaces for parameters, and returns an interface.
This analogy should make it clear:
You are building a building
The interface is the blueprint. It defines the basic structure, but what are you going to build with? What is the floor made of? What color are you going to paint the building with? Or should it be made of glass? I don't know; you only defined Material
, but you didn't specify what kind!
An abstract class can be used to restrict a Set<Material>
to a subset of those Materials. You want a house, but it can only be made of either brick or wood, not concrete.
You can't define this in an interface without your rules being overridden, so you need an abstract class.
The same can be said for various kinds of drivers, or any kind of interface representing a very broad array of objects.
An abstract class can be a subset of the interface for a particular portion of your API that implements it explicitly and does not make the abstract class a (package-private?) skeleton class.
If you don't need to enforce any kind of functionality in your rules, only types, then you can make an interface, but if you need logic, or code enforcement, abstract classes are the only possibility, and if that weren't so, you'd need a concrete class, but that would be something which you would need to look at the documentation for, as usually you expect concrete classes to have public constructors, not protected or private, unless they have a public factory to expose the constructors.
When I say you can make an interface, I mean an interface that overrides the parent interface, and an abstract class that overrides the parent interface. Where appropriate, an abstract class should be used in favor of an interface overriding an interface.
It can also be said that, considering you can use virtual multiple inheritance with interfaces, you can prevent hybrid classes. For example, in the driver API, you should not have a class that is the composition or hybrid of a graphics driver and a network driver. There should be the graphics driver object, the network driver object, and a bridge object for communication between drivers anonymously so that drivers remain decoupled and agnostic to other hardware.
Hence, in such case, defining separate GraphicsDriver
and NetworkDriver
abstract classes would be more efficient and maintainable than a mere interface.
@Wietlol are you satisfied now? I'm not trying again.
This Java 1.2 class I suppose tells what abstract classes were meant to do as I explained above.
/javadoc java.security.Permission