Why interfaces why not abstract classes?

why they are using interfaces concept in JDBC or struts2.0 why not abstract classes?
thanks in advance.

user5287726 wrote:
jverd wrote:
user5287726 wrote:
Interfaces are more flexible. For certain definitions of flexible, yes, but not for others.
A Java class can only inherit one class, but it can implement multiple interfaces.Which has absolutely nothing to do with why JDBC declares interfaces rather than abstract classes.How does your post even attempt to answer the OP's question?OP asked: "why they are using interfaces concept in JDBC or struts2.0 why not abstract classes?" I'm pointing out that your post does not address the question asked. And of course your answer is wrong anyway.
As for addressing the OP's question, I did that in my first response.

Similar Messages

  • When to use interface and when Abstract Class?

    In a recent interview I was asked "When to use interface and when Abstract Class?" Explain with an example.
    Also in what situations a class should be made final(real time example)

    Interface is a pure contract with no implementation. Typically used to define a communication contract between two different sub-systems. Example EJB home interface. This also allows the design to change as long as the contract is met.
    Abstract class is when there exists a lot of common functionality already known and can be coded. However, a few unknowns exists (typically about data) for which abstract methods need to be defined and implemented by the sub class.
    Example: Consider a workflow engine. A great example for abstract class. The workflow process has lot of common code that is independent of the workflow type (vendor flow, contract flow, payment flow etc). However, certain decisions on the route to take will depend on value of data being submitted. So the base class will define a abstract Data getData() method and proceed assuming data will come. The implementing subclass will provide the actual logic for getting the data.
    Also see the "Template" design pattern.
    Note: To some extent the common code design drives the behavior of the abstract methods. So if the design changes then so "might" the behavior expected from the abstract methods.

  • Diffrence between a Interface and a abstract class?

    Hi OO ABAP Gurus
    Please clear below point to me.
    Diffrence between a Interface and a abstract class?
    Many thanks
    Sandeep Sharma..

    Hi
    Abstract classes
    Abstract classes are normally used as an incomplete blueprint for concrete (that is, non-abstract) subclasses, for example to define a uniform interface.
    Classes with at least one abstract method are themselves abstract.
    Static methods and constructors cannot be abstract.
    You can specify the class of the instance to be created explicitly: CREATE OBJECT <RefToAbstractClass> TYPE <NonAbstractSubclassName>.
    Abstarct classes themselves can’t be instantiated ( althrough their subclasses can)
    Reference to abstract classes can refer to instance of subclass
    Abstract (instance) methods are difined in the class , but not implemented
    They must be redefined in subclasses
    CLASS LC1 DEFINAITION ABSTARCT
    PUBLIC SECTION
    METHODS ESTIMATE ABSTARCT IMPORTING…
    ENDCLASS.
    Interfaces
    Interfaces only describe the external point of contact of a class (protocols), they do not contain any implementation.
    Interfaces are usually defined by a user. The user describes in the interface which services (technical and semantic) it needs in order to carry out a task.
    The user never actually knows the providers of these services, but communicates with them through the interface.
    In this way the user is protected from actual implementations and can work in the same way with different classes/objects, as long as they provide the services required. This is known as polymorphism with interfaces.
    Interfaces features
    INTERFACE I_COUNTER.
    METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,           INCREMENT_COUNTER, ENDINTERFACE.
    CLASS C_COUNTER1 DEFINITION.   PUBLIC SECTION.
        INTERFACES I_COUNTER.
      PRIVATE SECTION.
        DATA COUNT TYPE I.
    ENDCLASS.
    CLASS C_COUNTER1 IMPLEMENTATION.
      METHOD I_COUNTER~SET_COUNTER.
        COUNT = SET_VALUE.
      ENDMETHOD.
      METHOD I_COUNTER~INCREMENT_COUNTER.
        ADD 1 TO COUNT.
      ENDMETHOD.
    ENDCLASS.
    Refer
    https://forums.sdn.sap.com/click.jspa?searchID=10535251&messageID=2902116
    Regards
    Kiran

  • Why use abstract classes?

    Why should I use abstract classes instead of a regular class with empty method bodies? Just better design? Is there some logical or performance based reason?

    Why should I use abstract classes instead of aregular
    class with empty method bodies? Just better design?Is
    there some logical or performance based reason?Because it describes what you're doing.
    If you define a "regular" class with empty message
    bodies, everyone who looks at it will say "WTF is he
    trying to do" or, if they're charitable, "Look,
    Harvey, someone who's trying to make Java look just
    like C++!".
    sigh Maybe answers like THIS are why people keep asking the same question.
    Here's a couple things an abstract class does that a "regular" class with empty methods bodies doesn't:
    1) An abstract class cannot be instantiated.
    2) An abstract class forces it's abstract methods to be implemented.
    If you were to extend a non-abstract class with empty method bodies, you wouldn't have to override the methods... you could just leave them empty. An abstract class forces it.
    There's a lot more reasons... those are a couple obvious ones.

  • Why require cap file why not only class file as in java

    why do we convert .class to .cap file why not simply load the .clss file to the card

    If Java Card has to accept .class file, it's certain
    that JCVM developers are going to spend more and more
    nights in their office.
    Just kidding. I'm one of them.LOL :)
    Put the CAP file converter on-card.

  • Why how Abstract class   for java.util.set

    I need to use Set i din't find any impelemnted class for Set, i don't want HashSet or LinkedHashSet just a Set is enough for my purpose.
    How can i take instance of AbstractSet it is abstract.....
    Is the only way is to write my own class extending AbstractSet.
    Or is there something which i'm missing
    TIA Nas

    Because Vector isn't an ancsetor of AbstractList.
    What you are trying to do is the same as saying that becasue my cousin and I have the same grandfather we must have the same parent which isn't true.
               Collection
            Set         List
       AbstractSet      AbstractList
       HashSet              Vector

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

  • Difference between abstract class and interface

    Hi everyone,
    CAn anyone explain why the following happen????
    Abstract class can have a constructor, Interface cannot.
    Abstract class can have static methods, Interface cannot.

    What are the advantages of defining constant
    variables in Interfaces?Not many.
    Effective Java - Joshua Bloch, Chapter 4, Item #17: Use interfaces only to define types.
    The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface.
    In summary, interfaces should only be used to define types. They should not be used to export constants.

  • Why  AWT (Abstract Window Toolkit) is use Abstract word? What AWT hiding?

    Hi i just want to know why sun microsystem used Abstract keyword while defining AWT and why not other classes like String, Exception, etc are not Abstract????
    Kindly Explain me

    Encephalopathic wrote:
    masijade. wrote:
    AWT is not a Class, it is an entire API, so the question makes no sense.I'm not so sure about that. It's got me to thinking, just what were they hiding?The native code of the underlying windowing platform

  • Interfaces, Abstract Classes & Polymorphism

    I have a friend taking a Java course as part of a larger degree program, and she's asked for some help with an assignment. The assignment is as follows:
    This assignment is to write a simple encryption/decryption application.  There will be a single application
    that the user can use to encrypt or decrypt a phrase passed in on the command line, with the user deciding
    which encryption/decryption scheme to use.
    The first scheme is to add 1 to each character that is in the phrase, the other is to subtract 1 from each
    character that is in the phrase.
    To encrypt, you must be able to use the follwing syntax:
    java Crypto encrypt Additive "hello"
    Output:
    "hello" encrypts to: "ifmmmp"
    To decrypt:
    java ca.bcit.cst.comp2256.a###### decrypt Additive "ifmmp"
    Output:
    "ifmmp" decrypts to: "hello"
    Use Additive or Subtractive as the arguments to choose which encryption/decryption to
    use. The problem is, I'm not entirely sure how to use abstract classes and interfaces to do what is being asked. I'm pretty sure I could do the whole program in a single for-loop, but apparently her teacher doesn't want people coming up with their own solutions for the problem. I don't need any code for how to do it, per se, I'm just wondering how one would structure a program like that to include interfaces, polymorphism and abstract classes.
    Anyone have any ideas?

    with the user deciding which encryption/decryption scheme to use.This is the key sentence. encryption/decryption can be done using multiple schemes. The contract for any given scheme can be defined using
    public String encrypt(String input);
    public String decrypt(String input);There can be multiple implementations for these methods, one set for each scheme.
    The contract therefore becomes the interface and each implementation is a concrete implementation of this interface.
    The problem doesn't delve deep into the kind of schemes available. If it does and there is a significant overlap between 2 schemes, an abstract class that takes care of the shared logic among 2 schemes comes into picture.
    Hope this helps!

  • When should I use abstract classes and when should I use interfaces?

    Can any body tell me in which scenario we use /we go for Interface and which scenario we go for abstract class, because as per my knowledge what ever thing we can do by using Interface that thing can also done through abstract class i mean to say that the
    behavior of the two class.
    And other thing i also want to know that which concept comes first into the programming abstract class or Interface.
    S.K Nayak

    The main differences between an abstract class and an interface:
    Abstract
    An abstract class can contain actual working code (default functionality), and can have either virtual or abstract method.
    An abstract class must be sub-classed and only the sub-classes can be instantiated. Abstract methods must be implemented in the sub-class. Virtual methods may be overridden in the sub-class (although virtual methods typically contain code, you still may
    need/want to override them). A good use for an abstract class is if you want to implement the majority of the functionality that a class will need, but individual sub-classes may need slightly different additional functioality.
    Interface
    An interface only contains the method signatures (method name and parameters), there is no code and it is not a class.
    An interface must be implemented by a class. An interface is not a class and so it cannot be sub-classed. It can only be implemented by a class. When a class implements an interface, it must have code in it for each method in the interface's definition.
    I have a blog post about interfaces:
    http://geek-goddess-bonnie.blogspot.com/2010/06/program-to-interface.html
    (sorry, I have no blog posts specific to abstract classes)
    ~~Bonnie DeWitt [C# MVP]
    http://geek-goddess-bonnie.blogspot.com

  • Abstract classes, Interfaces, and concrete classes

    I have another technical interview tomorrow and somehow I keep getting asked the same question and I feel my answer is not really up to par. The question is:
    "What is the advantage of subclassing an abstract class versus concrete class?"
    "What is the difference of using an interface versus an abstract class, which is better to use?"
    For the first question, I usually answer performance is the advantage because you don't have to instantiate the class.
    For the second question, I usually say that you can put implementation in an abstract class and you can't in an interface. I really can't answer the second part to this question.
    Any ideas?

    For the first question, I usually answer performance
    is the advantage because you don't have to instantiate
    the class. Try invoking the class B in the following somewhere in another class.
    abstract class A{
       A(){
          System.out.println("abstract instantiated");
    class B extends A{
      B(){super();}
    }

  • Documentation formats for interfaces, classes, abstract classes

    I am writing docs and want to make sure it conforms to best practices. Here is what I am doing:
    interfaces = [italics, not bold]
    classes = [not italics, bold]
    abstract classes = [italics, bold]
    I am most unsure of abstract classes?
    That is important to me, so please help me get this straight. thanks.

    Everybody knows that interfaces are blue, classes are red, and abstract classes use jumpy text.
    (that was a joke by the way)
    To my mind, using bold for abstract classes would be misleading. Just on an intuitive level, bold seems more concrete. But that's just me. I think the best thing to do is just to decorate the names with "<<interface>>" or "<<abstract>>" so there's no confusion.

  • Can interface extend abstract class?

    Can interface extend abstract class?
    I tried to make a interface extend an abstract class but i got an error stating:
    interface expected here.
    Can anyone help me ?

    > ok, but can an interface implement an abstract class?
    No. An interface provides no implementation whatsoever. An abstract class can implement an interface, but not the other way around.
    http://java.sun.com/docs/books/tutorial/java/concepts/interface.html
    ~

  • Hi all,Interface vs Abstract class

    Hi, All When We are going to use interface or an Abstract class,Can tell exactly
    Thanks in advance

    Interface class is used to contain methods that is to be defined by children classes. And abstract class, even though you can have all methods being abstract, but normally I would use this class for situation such as implement methods that are general enough to be used by the children classes and left others being abstract to be implemented by children classes later. I always think this relationship in a simple way:
    Abstract Class: Animal
    Interface : Leg, Tail, Hair, Feather, Head...
    Children classes: Tiger, Bird, etc.
    Thus, for class Animal class you can have methods such as:
    Abstract: canRoar, canSing, canFly, ...
    Non-abstract: isSleeping, isAlive...
    More example:
    Tiger extends Animal implements Leg, Tail, Head, Hair
    Bird extends Animal implements Leg, Feather, Head
    I could be wrong, correct me if so. Cheers.

Maybe you are looking for

  • Year old iPad2

    My year old iPad 2 tells me that it is not charging. It currently has a 13% charge and will not charge with the adapter for an a/c outlet or connected to my Mac. Is my battery finished or is there another fix?

  • How do I download a DVD to my iMac?

    I'm new at this, have not tried this before.  I have a privately made DVD of a one-act play I produced this summer.  I want to download it to my iMac so I can upload it to my website's server.  I have not found a "download" feature under Finder or el

  • Long Purchasing Doc Item Text

    I am having an issue with out Purchase Order Smartform.  Our users input item text for their PO's that can be lengthy at times.  What I need to know is if there is a way I can make these long item texts automatically wrap to the next page?  Is there

  • ARIS - Solution Manager synchronization limitations

    Hello, I made simple demo and I noticed that there are several limitations in ARIS<->Solution Manager synchronization. Could You explain me some issues or tell how to solve them, that would be very helpful. 1. When I make model in SolMan and then imp

  • Username Format first.last vs. firstlast?

    I'm currently setting up the domain using Mac OS X Leopard Server for a client. Their email address are currently in the [email protected] format. It seems like I could get it to automatically set up email on a new machine using MCX if the company ha