Sunday, 13 March 2016

Interface vs abstract class

It may be confusing at the start. I think it should be explicit as term's literal meaning.

Interface is a communication protocol defines how a class of instances interacts with the external world, i.e. other instances. So interface method is about abstract instance methods.

Abstract class is a place to put common attributes and methods of a class in one place. It could be class or instance members.

Interface and abstract class are abstract, so they won't have any implementation. One class can implement several interfaces, depending on how many deceives or channels via which it interacts with the external objects. Abstract class could have implemented method and fields. They are common members of the class or its instances.

Interface can only define constants, and fields defined in the interface are implicitly considered as 'public static final'. Interface abstracted methods can only be defines as public, for they are used as communication to the external.

Abstract class as explained before, as explained it is a common place to put all the common features in one place; so you may define member access, as public, protected, default, and even private.

We can define constant and abstracted method in the interface; in the java 8, we may declare static method also in the interface.




No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...