How coding to Interface and Inheritance helped me reuse code

Before going into the details I will state the requirement:

  • I need to fetch certain records from 3 different tables into 3 ArrayLists.
  • I have 3 Classes which store the information: Lets name it- Class1, Class2, Class3.
  • All the above 3 classes implement the Interface, lets name it Interface1. The interface has a method called init(). The main task of init() is to initiate the values of the instance variables with the values obtained from the ResultSet (database). This instance is then added to one of the 3 lists define above depending on the type of the reference.

Read more

Things one has to know about Interfaces in Java

The following article is mainly focused at beginners who are not much familiar to Java. It can also be a quick recap tool for Java Developers.

What are Interfaces?

Interfaces are 100 percent abstract classes i.e it defines only abstract methods and constants. But while an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Interfaces can be implemented by any class from any inheritance tree.

Why do we need Interfaces?

Interfaces help in implementing “Multiple Inheritance” the Java Way. Now what exactly does it mean by “Multiple Inheritance”? The Multiple Inheritance, one in C++, is allowing a particular class to extend/inherit from more than one class. Multiple Inheirtance can be quite messy and lead to deadly situation at times.

Read more

Interface Vs Abstract Class

There are three differences between an interface and an abstract class: you can implement multiple interfaces at the same time, but only extend one class, an abstract class is allowed to contain implementation (non-abstract methods, constructors, instance initializers and instance variables) and non-public members, and abstract classes may be a tiny bit faster (or they … Read more

%d bloggers like this: