Q)What is an interface object?
=>In fact, object of an interface can’t be created. I.e. an interface can’t be instantiated.
=>However, interface object means, reference is of interface type and object is of its
implementation class type.
Q)What is the realtime usage of an interface?
=>An interface is used to interface(interact) with objects in Java applications.
=>Interface provides loose coupling between service requestor and service provider.
=>An inteface provides contract between service provider and service utilizer.
=>For eg. in JDBC, almost all are interfaces only. Usage of interfaces provides
JDBC driver vendor independency to our JDBC programs.
Note:- Coding to interfaces is always superior to coding to classes.
Q)What is a factory method?
=>A method that creates an object and returns the reference of that object to the caller
is known as a factory method.
=>We have two kinds of factory methods.
1)static factory method
2)instance factory method.
For eg.
Connection connection=DriverManager.getConnection("","","");//static factory method
Statement statement=connection.createStatement();//instance factory method
ResultSet resultset=statement.executeQuery("SELECT ...");//instance factory method
=>In fact, object of an interface can’t be created. I.e. an interface can’t be instantiated.
=>However, interface object means, reference is of interface type and object is of its
implementation class type.
Q)What is the realtime usage of an interface?
=>An interface is used to interface(interact) with objects in Java applications.
=>Interface provides loose coupling between service requestor and service provider.
=>An inteface provides contract between service provider and service utilizer.
=>For eg. in JDBC, almost all are interfaces only. Usage of interfaces provides
JDBC driver vendor independency to our JDBC programs.
Note:- Coding to interfaces is always superior to coding to classes.
Q)What is a factory method?
=>A method that creates an object and returns the reference of that object to the caller
is known as a factory method.
=>We have two kinds of factory methods.
1)static factory method
2)instance factory method.
For eg.
Connection connection=DriverManager.getConnection("","","");//static factory method
Statement statement=connection.createStatement();//instance factory method
ResultSet resultset=statement.executeQuery("SELECT ...");//instance factory method