‎2008 Jun 04 7:46 AM
Hi,
I have to buid a report in ECM with complete details of the engineering as well as production. This include workflow as well as various fucntionality depends upon the criterion and user's event.
I am implementating in OOPS and I Want to know that when I should use the Abstract class and when interface ?
Because as per me both serve the same purpose. Kindly send me the exact difference so that i can efficiently use the same.
Thanks
Prince
‎2008 Jun 04 7:49 AM
Abstract Class
class which have atleast 1 method which is declared only , (no definition is given for it in this class is mentioned as Abstract Method )
and that class is defined as Abstract class
Interface :
only declaration of method done here , no method will be defined here , class which will implement this interface will give definition .
Diff. b/w Abstract Class and Interface :
ABS Class can have method with there definition , but one method should be there with declartion only.
Interface will have all method with out definition .
The methods of an abstract class may contain default implementations for the sub-classes. The same is not possible with interface methods which are always empty.
‎2008 Jun 04 7:55 AM
hi
abstract class : in these class we can declare the metthods and optionally can give definition of method.
but at least one method must be there which is not defined in this class.
so that we can describe this class as ABSTRACT.
class who define definition of its methods called CONCRETE CLASS.
INTERFACE : u cannot give definition of method in it , u can only declare methods here .
reward if helpful.
‎2008 Jun 04 10:13 AM
Hi,
How can we take decision about when we have to use Interface and when Abstract Class.
Basicly abstact class is a abstract view of any realword entity and interface is more abstract one. When we thinking about the entity there are two things one is intention and one is implemntation. Intention means I know about the entity and also may have idea about its state as well as behaviour but donu2019t know about how its looks or works or may know partially. Implementation means actual state and behaviour of entity.
reward if helpful
regards,
preet
‎2008 Jun 04 1:11 PM
You have a superclass and subclasses. It there is at least one method in the superclass that will always be implemented differently in subclasses, and you never want the superclass instantiated, then define the superclass as abstract, along with those methods that always be implemented differently in subclasses.
An interface can be viewed as an all-abstract class. But it's more than that. Interfaces are used to enabling the handling of quite different objects which still have a set of shared characteristics. Imagines classes A and B that both implement interface I,. I can then create a method in class C that takes as an importing parameter a reference to a type I object. This means I can pass both A and B to the method in class C. Even though A and B might be completely different.
Interfaces are also used to mark classes with a particular property - e.g. serializable.
So, it's not really "abtract classes" vs "interfaces". You use whichever is appropriate to whatever it is that you're trying to program.
‎2008 Jun 05 4:36 AM
‎2008 Jun 05 5:56 AM
When inheriting A Interface We have to inherit all the methods of the Interface there's no other option whereas with abstract classes we can inherit the members that we are in need of.
Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in the case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.
Interface contains all abstract methods,all methods compulsory implemented by particular class, interface does not contain Constructor
abstract classes are designed with implemantion gaps for sub-class to fill in.
interfaces are sintacticlly similar to classes but they lack insance variables & methods.
abstract classes can also have both abstract methods & non-abstract methods. where as in interface methods are abstract only, & variables are implicitly static&final
regards
Preetesh
‎2021 Aug 06 4:01 PM
Regards,
Tanuja.