user3747720 user3747720 - 9 months ago 46
Java Question

Extend abstract class which implement another class

I am very new to OOP and going through a project code related to parser.
This contains following classes and interface.

public interface Parser {

public abstract class AbstractParser implements Parser{

public class CSVParser extends AbstractParser{

public class XMLParser extends AbstractParser{

I am not able to understand why it is done?


Its a basic OOP design, Its basically an example of "Program for Interface rather than implementation", To be more clear read once about SOLID design principles.

Now here in this code, There is an Parser interface, so If any class is a Parser then it must implement it, So again, If we want to give some default behavior to every parser, that's why there is AbstractParser.

To understand this code, you must see once JDK source code of Collections. Here You will see, List, Set, Map are interfaces, then you have AbstrictList, AbstractSet, AbstractMap classes which are defined as abstract and have default implementations for some methods like size(). Then you have concrete implementation like ArrayList, HashMap, HashSet which you can instantiate. I will suggest you once go through the Collections framework design, and SOLID principles as well.