Why to use Interface if methods are not implemented??

Hello,
I am having a problem to clearify as, why to use the interfaces which defines only methods and no implementation??
When a class implements an interface the methods are implemented by the class itself, don't you think that the same functionality can be achieved if the class defined the method itself...
The why to use interfaces, just that the same method name can be used by many classes or some other reasons..

did you google on that? There is lots of information I am sure explaining why you code to an interface defined type rather than a class defined type.
However, fundamentally you are correct, classes define their own type. The idea is that you use an interface because it allows you to have more than one implementation. Plus you can more easily change the structure of your program if you later wish if you did not use the class type directly.
You get better answers if you ask in the Patterns forum below.

Similar Messages

  • Why addcomponent and removecomponent method are not in component class,

    Hi,
    why addcomponent and removecomponent method are not in component oand component class,
    Thank you

    java.awt.Container has the appropriate add and remove methods:
    http://java.sun.com/javase/6/docs/api/java/awt/Container.html
    If that seems odd to you, you need to think about the Composite Pattern:
    http://en.wikipedia.org/wiki/Composite_pattern
    [url #" style="display: block; background-image: url('http://upload.wikimedia.org/wikipedia/en/1/13/Compositepattern.png'); width: 406px; height: 271px] 

  • EJB deployment problem --New remote interface class files are not loaded

    Hi, I face a problem while deploying an ear file in oc4j. I basically get some problems like the method in the remote interface is not implemented in the EJB class. But the implementation is actually available in the EJB class.
    We get this problem when we actually change the signature of the EJB remote methods. The new methods are not referenced by oc4j. Only the old version of remote interface is referenced by oc4j. But the latest version of EJB class is taken. I am using 9.0.3 version of the oc4j. Could you pls help me regarding this problem ?
    Regards
    Solomon

    I have found the solution :-)
    You must add to the ejbCreate() method of the bean class throws javax.ejb.CreateException

  • HT4059 Why Indian authours and Indians books are not available in your iBooks store.

    Why Indian authours and Indians books are not available in your iBooks store.

    Thats because Indian publishers may have not signed an agreement with Apple. Worst part is even if I want to publish a book for free using official iBooks Author, it does not publish on Indian iBooks Store.

  • I am using illustrator CC there are not showing scale size pointer in any object?

    I am using illustrator CC there are not showing scale size pointer in any object? Anyone tell me why it was does it? And how i can come again on that position?

    Or maybe Cmd(Ctrl)-U which is the toggle for Smart Guides?

  • Why IPC uses CRM as database and not R/3 ?

    Hi ,
    can any one help me with an answer for the following question :
    <b>Why IPC uses CRM as database and not R/3 ?</b>
    Points will be rewarded for helpful answer
    thanks
    ritu

    Hi
    IPC have Sales Pricing Engine, Pricing Configuration engine and TTE which helps to maintain the similar R3 pricing settings. As you are aware pricing in R3 is determined by Sales area, Cupp, DPP, so IPC is capable of determining the Pricing using same R3 standard procedure. T
    This is not available in CRM, so CRM needs IPC to undertake the determine pricing/ calculate the pricing of the products.
    Regards
    Nagarj

  • Can anyone help me as to why my raw files in bridge are not showing as thumbnails as they normally do . I can seem to fix it

    Can anyone help me as to why my raw files in bridge are not showing as thumbnails as they normally do . I can seem to fix it

    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    A screen shot of your settings or of the image could be very helpful too,
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Just got an iPad mini 3 and have not reset my iPad mini 3; is that why the photos from iCloud backup are not showing up in the new iPad?

    Just got an iPad mini 3 and have not reset my iPad mini 3; is that why the photos from iCloud backup are not showing up in the new iPad?

    Sorry, don't know what you are asking. You have an old iPad Mini 3 and a new iPad Mini 3?  How did you set up the new iPad? Did you restore it from a backup of the old iPad? What photos are you not seeing?
    Cheers,
    GB

  • Using custom classes that are not beans

    Hi folks,
    Is it possible to use java classes that are not beans. I mean, on a page, could you say Customer cust = new Customer("Jones", 25);
    if you had a Customer class with a constructor that took a name and age (String and int).
    If so, how do you go about this- do you need to import the class, or put it in a standard location? I'm using Tomcat, and would guess that this would go in WEB-INF/classes?
    I hope it's not a stupid question, all the literature seems to be focused on JavaBeans
    Any advice on this would be great!

    Beans are used as putting Java code into a JSP is generally considered bad practice. The advantage of the bean pattern is that you use things like:
    <jsp:setProperty name="laBean" property="someSetter" value="someValue" />so that you aren't embedding Java directly into the JSP. I'm not very religious about this particular topic personally and will throw a line or two in here and there.
    Having said that though, you can easily use any Java class in a JSP. You'll have to import it first:
    <%@ page import="java.util.*" %>And then you can easily use it like in a real Java program.

  • I have 111 files to send. Why only 50 files. You are not very smart to do it this way.

    I have 111 files to send Why only 50 files. You are not very smart to do it this way.

    Hi,
    If you want to send more than 50 files, you can zip them up into a single file and send them that way. (Note that zip files aren't previewable by the recipient. They need to be downloaded.)
    You might want to check the thread: Re: Is there any way around the limit of 50 files in Adobe Send?
    The feedback has been sent to the engineering team to consider.
    Regards,
    Rave

  • Method "equals" not implemented for class "Pan1"

    Method "equals" not implemented for class "Pan1" -- this is the error I'm getting while running one static Analyzer. Can anybody say, what is this error , and how to rectify it ?

    The static analyzer may have noticed that either you may invoke .equals() on instances of this class (possibly through polymorphism) and you have not implemented the method in your class. This is most likely a warning since many times lack of an implemented .equals() method in such cicumstances will lead to Object.equals() being executed and that simply checks to see if the object references are the same - quite a bit stronger than what one would probably expect from .equals();
    it is also possible that you did implement an equals() method but that you used the wrong argument type. This is a common mistake:
    public boolean equals(MyClass other) {
       return /* something */;
    }This type of warning may be ignored, or if it troubles you and there is no way to disable it for the classes that you know you have implemented correctly, you might consider adding an equals method of the form:
    public boolean equals(Object other) {
       return super.equals(other);
    }Chuck

  • This JDBC 2.0 method is not implemented

    I tried to use jDriver for MSSQL and use the following jdbc code :
    stmt.prepareStatement(" SELECT xxxx FROM yyyyy WHERE zzzz = ? FOR UPDATE "
    ,ResultSet.TYPE_FORWARD_ONLY,
    ResultSet.CONCUR_UPDATABLE );
    stmt.setCharacterStream (n, value);
    Both get this exception : This JDBC 2.0 method is not implemented
    Is jDriver a JDBC 1.x driver only. Thanks.
    Chris

    Yes, our MS driver is in fact jdbc1.0-compliant only. For a more
    current driver you can try the free one from MS, or www.inetsoftware.de
    Joe
    Christopher wrote:
    >
    I tried to use jDriver for MSSQL and use the following jdbc code :
    stmt.prepareStatement(" SELECT xxxx FROM yyyyy WHERE zzzz = ? FOR UPDATE "
    ,ResultSet.TYPE_FORWARD_ONLY,
    ResultSet.CONCUR_UPDATABLE );
    stmt.setCharacterStream (n, value);
    Both get this exception : This JDBC 2.0 method is not implemented
    Is jDriver a JDBC 1.x driver only. Thanks.
    Chris

  • JDBC 2.0 method is not implemented : weblogic.jdbc.mssqlserver4.TdsResultS

    Hey Guys,
    We are running our application on weblogic8.1 server (AIX box). Our application keeps throwing this error. Has anyone of you come across this error before.
    java.sql.SQLException: This JDBC 2.0 method is not implemented at weblogic.jdbc.mssqlserver4.TdsResultSet.getType(TdsResultSet.java:684) at weblogic.jdbc.wrapper.ResultSet_weblogic_jdbc_mssqlserver4_TdsResultSet.getType(Unknown Source) at weblogic.jdbc.rmi.internal.ResultSetImpl.isResultSetCacheable(ResultSetImpl.java:140) at weblogic.jdbc.rmi.internal.ResultSetImpl.isRowCaching(ResultSetImpl.java:109) at weblogic.jdbc.rmi.internal.ResultSetImpl_weblogic_jdbc_wrapper_ResultSet_weblogic_jdbc_mssqlserver4_TdsResultSet_WLSkel.invoke(Unknown Source) at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477) at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144) at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415) at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java(Compiled Code)) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178) Thanks Regards Richi

    Rachith Srinivas wrote:
    Hey Guys,
    We are running our application on weblogic8.1 server (AIX box).
    Our application keeps throwing this error. Has anyone of you come across
    this error before.
    java.sql.SQLException: This JDBC 2.0 method is not implemented
    at weblogic.jdbc.mssqlserver4.TdsResultSet.getType(TdsResultSet.java:684)
    ...Hi. That old driver is telling you the truth. That JDBC 2.0 method is not implemented.
    There has been no development of that driver since soon after the JDBC 2.0 spec was
    finalized. We provide the weblogic.jdbc.sqlserver.SQLServerDriver in the 8.1 server,
    and heartily recommend you switch to it. It's a much superior driver, and has the
    considerable benefit if being fully supported and updated. The old ms4 driver is
    strongly deprecated and won't exist in the next release of WebLogic.
    Joe

  • ClientMethods in Interface of ApplicationModule are not public - why?

    Hi
    I realized (with some surprise) that all declared client methods in the interface of an application module are not public. Why? Is there a specific reason or is this a bug?
    Example:
    - Create a simple ApplicationModule "MyApplicationModule" (not remotable)
    - Write a simple method "public void myMethod()" in MyApplicationModuleImpl
    - Use the ApplicationModule-Wizard Tab "Client Interface" to shift "myMethod()" to the client In side
    => JDeveloper generates several Files, one of these is "MyApplicationModule.java".
    => in MyApplicationModule.java method "myMethod" is defined but without the "public" modifier.
    I guess this is a bug.
    Thanks for your help

    Yes, you are right.
    I just stumbled over this fact (which I didn't realize yet. <blush/>) because the methods were flagged as "not accessible" in the editor. They became "accessible" as soon as I added the "public" modifier to the method definition in the interface.
    But now, after I restarted JDeveloper the editor does not flag the methods anymore even without the "public" modifier.
    Seems as if the Editor sometimes forgets this rule too ;-)
    Thanks for your help

  • Why we use interfaces ?

    hi all!
    i m confused that what is the advantage of using interfaces for classes if it is for security,data hiding pupose then we can use private modifiers,then y is this think built in java and which r the cases in which we must use interfaces and y?
    plz give me any simple example to understand ur point
    thanx in advance.
    sajjad ahmad

    Hmm... First, I'm sorry about my English... but i will try.
    In C++ we can use multi-inheritance that let the developer "extends" one or more classes.
    eg.
    class Hello extends A,B,C,D
    This case can be happened in C++.
    But If both class A and B have a method call "void sayMyName()"
    How can we refer which method was called when we call "Hello.sayMyName()"
    A.sayMyName() or B.sayMyName()
    So java don't allow this thing happen.
    Java allow developers to extend "only one class"
    but to enable multi-inheritance ability Java allow developer to implement more than one class.
    That is "interface" which was implemented.
    Now lets talk about it's benefits.
    Interface is not for security or data hiding purpose.
    But interface is used for "make a template".
    When I created one class called Hello.
    But I have created another class too.
    Now I want to make sure that my classed have a method "void say()"
    What can I do ?
    1. Make some class that have a method "void say()" and let my classes extend it.
    2. Make an interface and implement it.
    Choise number one is quite good ... but !!!
    If I have to extend some another class that is more important such as "Applet"
    Now I can't extend another class.
    I need only method "void say()". But I don't care what it does.
    So I make an interface that force the implementing class to create a method "void say()"
    and I implement it.
    Question: Why I have to implement this interface ? If I only define a method "void say()"
    The problems is gone ....
    Answer: That may be true if I want them to have a method. But how can I refer to them.
    Lets see this code.
    class A extends Applet {
    void say() {System.out.println("My name is A");}
    ... go on ...
    class B extends Applet {
    void say() {System.out.println("My name is B")}
    ... go on ...
    class GO {
    public void letMeSay(............. o) {
    o.say();
    What can I fill in the argument of method "letMeSay()"?
    Object ? Object doesn't have a method "void say()"
    Applet ? With the same reason.
    Now lets see another code.
    interface Sayable {
    abstract void say();
    class A extends Applet implements Sayable {
    void say() {System.out.println("My name is A");}
    ... go on ...
    class B extends Applet implements Sayable {
    void say() {System.out.println("My name is B")}
    ... go on ...
    public void letMeSay(Sayable o) {
    o.say();
    It's ok right ... I can refer to interface "Sayable" that can "say"
    Next benefit of interface ... "define Constants field"
    We can define constants in an interface and implements it to everywhere we want to use those constants. When we change a value in this interface ... Constants in another place will be changed too .... that is very useful ....(But this may have change in J2SE 1.5 ... see more info)
    "I HOPE THIS REPLY MAY GIVE YOU SOME KNOWLEDGE ... GOOD LUCK WITH PROGRAMMING"

Maybe you are looking for

  • How to open a idml file created by CS6 in CS5?

    I created a file in InDesign CS6 and saved as idml file yesterday. But today I can not open either in CS6 or CS5 version. It says "Cannot open the file "Project #3.idml". Adobe InDesign may not support the file format, a plug-in that supports the fil

  • How can i write to ntfs device

    how can i write to ntfs device from mac

  • My fonts are not working correctly

    Hello guys, I noticed today that most of my added fonts are not working. I use a lot of fonts that have a cyrillic subset which were working perfectly fine till 2 days ago. Now when I select a text field and try to change the font face to one of the

  • Question for ORACLE EXPERTS!!! PERFORMANCE PROBLEM!!!

    I have 2 nodes on RAC. On node1 the following query run in 15 seconds and on node2 the same query run in 40 minutes. This is a big problem because we are migrating a SQL Server database to Oracle RAC 10gR2 (10.2.0.2) on HP-UX Itanium and we can´t fin

  • Can my macbook 5.2 take ddr3 memory?

    Can my macbook 5.2 early 2009 take ddr3 memory? I have upgraded it to 4gb ddr2, but could I upgrade it further to ddr3 8gb? I have read somewhere you can but just to be sure.