perry arora
Posts: 22
Nickname: perry
Registered: Sep, 2003
|
|
Re: INTERFACE vs ABSTRACT
|
Posted: Oct 22, 2003 5:01 AM
|
|
hi Right said friend
The very basic differnce or the point of distinction is that what do you want to use !!
If u want to inherit any Basic structure for your object you shoud use the abstract class reason being when you inherit the class you are forced to follow a structure for using it.
ok... check the following DATA .. its need to scan it!
INTERFACE VS ABSTRACT CLASSES
(1) THE IMPLEMENTOR/SUB CLASS SHARE A COMMON STATE&BEHAVIOUR OR THEY SHARE METHODS SIGNATURE
(3) INTERFACE CAN NOT PROVIDE ANY DEFAULT CODE
(4**) CLASSES CAN DEFIN THE CORE IDENTITY OF THEIR DECENDANTS , BUT THE INTERFACE DESCRIBE THE PERIPHERAL IDENTITY E.D AUTOMOBILE CLASS CAN USE THE RECYLE INTERFACE WHICH COULD BE APPLIED TO MANY UNRELATED CLASSES
**(5) INTERFACE ARE USED FOR THE CONCEPT OF DELEGATION WHEREAS THE ABSTRACT CLASSES DEFINE WHAT WE CALL INHERITENCE
(A)for e.g the best e.g is when we use the Runnable interface not extend the thread class.. when we use the runnable interface we do not create a separated thread infact . we want some code fratgement that can run independently.. or in other words we coud delegate the execution line to it...
but when we use the thread class we create a complete new threas that coud also be given some inherit behaviour and state.
(B) the second best e.g is when we use the javax.sql.DataSource :: in this case we obtain the connection using this interface or in other words our code delegates this job to the data source implementation of the vendor .. whose data base we are using...
(6) THE ABSTRACT CLASS FORCESS AN STRUCTURE
when we extend that class with that we inherit the behaviour and t some state of the class also that can be good or bad ,, that can allow a limited or a free access ... in a way it imposes a structure..
but when ever we impmenet the interface it provides nothing more than a set of constants.. we have to take tools from other classes.. and we are free at the internal design..........
(7) INTERFACES ARE SLOW AND REQUIRE AN EXTRA INDIRECTION
(2) THIRD PARTY CLASS CAN ONLY EXTEND ONE SINGLE CLASS BUT CAN IMPLEMENT MULTIPLE INTERFACES
(8) INTERFACE ONLY PROVIDE THE public static constants CLASSES PROVIDE BOTH THE INSTANCE AND THE STATIC CONSTANTS - and also one can write an intialization code for intializing the constants .. which is not possible in the interfaces
(9) CHANGES ARE DIFFICULT TO REFLECT IN INTERFACES... WE CAN ATLEAST PROVIDE AN INTIAL CODE FOR THE ADDED METHOD IN THE CLASS if we add a new method to the interface we will have to track all the implementation of the interface to include that change
but if the same is the case with the classes in that case we can atleast provide an basic default implementation that all the descendants can use/....
Hope it will help U
bye
|
|