Using an interface as a type

Hi
Im reading someone elses code and theres something i dont understand. I read the sun trial on interfaces and see that an interface can be declared as a type by a class which implements said interface. Also that interfaces cannot be instantiated.
In the code a class named DictEngine which implements IDictEngine declares the following:
IDatabase[] fDatabases = new IDatabase[0];
IDataBase is an interface. All the classes and interfaces are in the same package. As i understand it an array called fDatabases of type IDatabase is being declared.
Basically i don't understand what this acheives, its possible to instantiate interfaces ?
Thanks

Not that the following code would be too useful, but
// create storage for 4 references to some object which implements comparable
Comparable[] c = new Comparable[4];
c[0] = "a string";
c[1] = new Integer(5);
c[2] = new Double(42.0);
c[3] = new Date();
so what i don't underatand is what type of object the array will reference since interfaces cant be instantiated.What ever you put in there

Similar Messages

  • The instance is using interface 'eth0' of type 'Unknown'.

    Hello,
    I've installed an oracle cluster 10.2.0.1.0 with two computer successfully.
    The two computer are SUSE linux ; "uname -a" display
    Linux dbprod1 2.6.13-15.8-smp #1 SMP Tue Feb 7 11:07:24 UTC 2006 x86_64
    x86_64 x86_64 GNU/Linux
    After a month I was obliged to change the subnet of eth0. So i must change the
    addresses of the 2 machines and the 2 VIP address.
    With the utility oifcfg I correct the information about the interface eth0. (I
    execute also vipca)
    oifcfg iflist
    eth0 10.23.11.0
    eth1 10.25.13.0
    oifcfg getif
    eth0 10.23.11.0 global public
    eth1 10.25.13.0 global cluster_interconnect
    Now in the EM I obtain this two warnings (one for each instance):
    mbprod_mbprod2: Interconnect; Interface Type;The instance is using interface
    'eth0' of type 'Unknown'.
    mbprod_mbprod1:Interconnect; Interface Type; The instance is using interface
    'eth0' of type 'Unknown'.
    How can I correct the problem?
    Thank you very much.

    Manorama wrote:
    Suppose we are using interface, to use the method declared in the interface, which is implemented in another class. Now what is the difference between using the interface instead of directly instantiating the implemented class to use the method. Can anyone explain me in detail.To use an interface an implementing class must be instantiated somewhere (though not necessarilly in your own code). The object in question is accessed through the interface, but in reality every Object is an instance of a concrete class. For example say you connect to a database. DriverManager gives you an object which implements java.sql.Connection. The object you get will actulay be of a class defined inside the database provider's libraries and which you may well not be allowed to instanciate yourself, all you need to know is that it implements Connection. And because you handle it as a reference to Connection, you don't need to care what the actual class is, you can change the database URL and switch to a completely different database driver without changing your code.

  • Message interface with two types of message types

    Hi experts,
    I am having problem that a proxy cannot be generated because  of the (mixed) types of the message types that the interface is using.
    The first message type is defined in the repository and another is defined as an external definition, imported in from an outside source.
    Here is the SAP message I received when I tried to generate the proxy for this interface.
    +++++++++++++++++++++++++++++++++++++++++++++
    Interface uses external and internal message definitions
    Message no. SPRX122
    Diagnosis
    In a message interface you can use messages from different sources:
    1. Message types and fault message types edited in the Integration Repository
    2. Messages imported into the Integration Repository (external definitions, RFC, IDoc)
    In the current message interface, message types from different sources have been used.
    Since messages from these different sources must be handled differently during proxy generation, such a mixture of messages within a message interface is not possible.
    System Response
    The interface cannot be generated.
    Procedure
    Change the interface definition accordingly in the Integration Repository.
    ++++++++++++++++++++++++++++++++++++++++++
    The imported xsd is quite large and also contain many large includes. I don't have the option of creating the message type manually.
    Any suggestions?
    Thank you,
    -michelle

    Hi all,
    I tried several things and the problem is still not resolved. This is what I learned.
    First of all, I believed the SAP message about mixing of internal and external message is misleading or even wrong. I tried with both message types being external but I still get the same message that the interface has one internal and the other external message type.
    Secondly, since Arvind suggested that I might have used an xml element that is not currently supported by ABAP proxy, I then change to another definition with the most simplest elements. I then attached this other definition to the interface and tried generating the proxy again. I still get the same system message that I am using mixing of message types in one interface.
    My conclusion is XI still is not capable of generating ABAP proxy from external definition.
    Does anyone have any comments/suggestion/experience on this issue?
    Best regards,
    -michelle

  • Using empty interface -- is there a better way to do this?

    Hi,
    I have a set of classes in different projects that I'd like to be referenced together, although they have different methods depending on which project they're from. To do so, I've created an empty interface for each of these classes to implement, so I can return a similar type and then cast it however I need to based on which project I'm using.
    However, I feel the approach of creating an empty interface just isn't the best way to do this. I've looked into annotations, but I don't think they can solve my problem. I don't think I'm being too clear here, so let me give a brief example:
    Here is one of the interfaces I use:
    public interface IceClient {
         public IceOperations operations();
    }Here is the empty interface:
    public interface IceOperations {
    }I have a method which will return a type of IceOperations:
         public static synchronized IceOperations getOperations(String clientName) {
              if (clientMap.containsKey(clientName)) {
                   IceClient client = clientMap.get(clientName);
                   return client.operations();
              } else {
                   System.out.println("No client of that name is currently running.");
                   return null;
         }This is all fine and dandy. I need to instantiate a new IceOperations object in my client code as such, where operations is of type IceOperations:
    operations = new DiagOperations();And finally return it like this, where client.operations() returns a type of IceOperations:
         public DiagOperations operations() {
              return (DiagOperations)client.operations();
         }Anyway I hope that wasn't too confusing. I cannot think of a different way to do this. Is there some way I can do this with annotations? The only other thing I can think of is just returning Object, but that seems ... icky.
    If I need to be clearer, please let me know.
    Thanks

    JoachimSauer wrote:
    I didn't understand them to be trick questions, but rather serious invitations to question and verify your assumptions.
    It might be the fact that every current implementation implements Runnable for some reason (possibly because it starts a Thread on its own). But it's entirely possible that you can produce a completely different implementation that doesn't need the Runnable interface and still be conformant.
    If every implementation of X needs to implement Runnable, then it could be a sign of a slight design smell. Could you give an example where you think it's necessary?Every implementation of my "X" interface is basically a class that acts as a communicator/listener of sorts until it's stopped by the user, similar to a server socket. Sometimes, it has to sit there and wait for events, in which case it obviously must be in its own Thread. Other times it doesn't have to do this; however if I do not start it in its own Thread, I will have to continually stop and restart the communication to invoke operations on the server, which is inefficient.

  • The use of interface in abap object

    hi,
    what is the use of interface in class? can have a simple example with explanation? i have read from help but not quite understand its purpose.
    thanks

    Hi El,
    Interfaces are pure abstract classes. The interface methods will have only definitions but no implementations.
    The classes which will implement interfaces has to provide the implementation to the methods.
    Interfaces will provide the common definition and the classes which implements these interfaces will provide them different implementation to the methods as per their requirements. This achieves Polymorphism of Object Orientation.
    REPORT zbc404_hf_events_3 .
    INTERFACE lif_employee.
      METHODS:
        add_employee
           IMPORTING im_no   TYPE i
                     im_name TYPE string
                     im_wage TYPE i.
    ENDINTERFACE.
    CLASS lcl_company_employees DEFINITION.
      PUBLIC SECTION.
        INTERFACES lif_employee.
        TYPES:
          BEGIN OF t_employee,
            no  TYPE i,
            name TYPE string,
            wage TYPE i,
         END OF t_employee.
        METHODS:
          constructor,
         add_employee      "Removed
            IMPORTING im_no   TYPE i
                      im_name TYPE string
                      im_wage TYPE i,
          display_employee_list,
          display_no_of_employees.
      PRIVATE SECTION.
        CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
                    no_of_employees TYPE i.
    ENDCLASS.
    CLASS lcl_company_employees IMPLEMENTATION.
      METHOD constructor.
        no_of_employees = no_of_employees + 1.
      ENDMETHOD.
      METHOD lif_employee~add_employee.
      Adds a new employee to the list of employees
        DATA: l_employee TYPE t_employee.
        l_employee-no = im_no.
        l_employee-name = im_name.
        l_employee-wage = im_wage.
        APPEND l_employee TO i_employee_list.
      ENDMETHOD.
      METHOD display_employee_list.
      Displays all employees and there wage
        DATA: l_employee TYPE t_employee.
        WRITE: / 'List of Employees'.
        LOOP AT i_employee_list INTO l_employee.
          WRITE: / l_employee-no, l_employee-name, l_employee-wage.
        ENDLOOP.
      ENDMETHOD.
      METHOD display_no_of_employees.
      Displays total number of employees
        SKIP 3.
        WRITE: / 'Total number of employees:', no_of_employees.
      ENDMETHOD.
    ENDCLASS.
    Check this link for some more examples on OO ABAP
    http://www.erpgenie.com/sap/abap/OO/eg1.htm
    Thanks,
    Vinay

  • How can I use USB interface in Labview?

    Hi.
    Does labview allow to USB interface?
    I have been seen allowing GPIB and RS232.
    I'm beginer at Labview and wanna use USB interface for my target system and pc.
    I wanna know how to labview interfaces from target system to pc.
    And if Labview doesn't provide USB interface module, how can I use USB?
    Is using a USB at Labview hard to beginer?
    Plz, answer to my quetion.
    sorry, my English is very poor.
    thx for reading my article.

    You can access devices connected to the USB port, but not in the same way as you would a GPIB or RS232 device. There are no USB drivers like there is VISA for GPIB or serial. Rather devices that plug into the USB appear to the systen as some sort of standard resource like a printer, disk drive or IO board. LabVIEW then interacts with these devices as it would any other device of the same type.Look at it this way, if you have a USB daq device you will access it through MAX the same as if it were a plugin card. Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Understanding the use of interface class?

    Hello,
    This question referes to java servlets, but the questions is about java design.
    My wrox java server pages text, includes an example where some user data is posted to servlet.
    To process the data posted and store this, they created a interface class and another class AdminManager which implements the interface.
    In the servlet they create an object from the interface class, and call the AdminManager methods through the interface object.
    In the book this was the only example which used a interface. And I wondered if this design approach was often used, or should an interface normally be used if several classes would implement the interface.
    Thanks

    It depends. You might want to create an interface even if you only have a single implementation of that interface in mind, because you want to make it easy to create more implemenations later.
    Also keep in mind that not all implementations of an interface are strictly for production use. For example, you might want to define an interface, define an implementation of that interface for production use, but then also define a "mock" version of that interface for testing, prototyping, etc.
    Generally I feel that if you have a sufficiently complex set of types and relationships between those types, it makes a lot of sense to express those relationships purely as interfaces, on a high level. Then provide implemenations as a separate step in the programming process.

  • Use of interface concept

    Hi everyone !!!
    Can anyone explain me what are the uses to the interface and why do we need to use interface.
    I know one advantage is java doesn't support multiple inheritance so we need to use interface.
    By using interface what can we do ? But i dont find advantages in that
    can you explain me pls ....

    One of the most popular uses of interfaces comes out of the Collections frame works.
    For example, java.util.List, java.util.Map, and java.util.Set.
    ArrayList is an implementation of the the interface List. By abstracting ArrayList into the interface, I can now change what type of List I am working with, and my code doesn't care....
    For example, I have a method that creates an ArrayList that contains all the users on the server at a particular time. As the coder, I know the method is going to create an ArrayList. Now I have a choice, I can make the method's return type an ArrayList, or I can use the interface name and return a List:
    public ArrayList getCurrentUsers() {
      ArrayList theList = new ArrayList();
      return theList;
    -or-
    public List getCurrentUsers() {
      List theList = new ArrayList();
      return theList;
    } Both codes would be functionally equivalent. Any code that calls the first method may (but does not need to) do this:
    ArrayList currentUsers = getCurrentUsers();Whereas any code that runs the second method would need to do this:
    List currentUsers = getCurrentUsers();What's the difference? Well, let's say you decide to change your method to use a LinkedList instead of an ArrayList. If you employed method 1, you now have to make sure you change all the code that accessed the method is changed as well. But, since LinkedList is another implementation of List, if you employ method 2, you can be sure that none of the code that uses your method will break, because they only work through an interface wich both ArrayList and LinkedList share in comon.
    So Interfaces are great for defining how a class or object looks, but not necessarily how it works. If you use the List interface to look at ArrayList or LinkedList then both of these classes will look the same, they are both sure to have the same methods defined in the List interface. However, they both will act differently, based on the underlying implementation.
    In general terms, it is a level of abstraction that allows the implementer be more flexible with what he is working on, by ensuring a common means of accessing the object, or a set of rules that users must use when accessing the object. In the mean time, the coder is free to make changes, switch implementations, without affecting others.

  • Use of interface, abstract

    Hi all
    A simple question, I have been read some books or web sites about the use of interface, abstracts, but I still don't quite get it such as when should we use it, how should we apply it in terms of programming design..
    Can someone teach me or show me some example....
    Thanks!

    user978043 wrote:
    A simple question, I have been read some books or web sites about the use of interface, abstracts, but I still don't quite get it such as when should we use itAlmost always, especially in non-trivial cases.
    how should we apply it in terms of programming design..Jverd's already given you a good example, but just to reinforce it for you: an interface describes the WHAT; a class defines the HOW.
    An abstract class is somewhere between the two, and is often used for 'skeleton implementations' (you may want to Google it), which allow you to build your own concrete (non-abstract) classes very easily.
    Can someone teach me or show me some example.... This one is filched from "Effective Java" and converts an array of any reference type into a fixed-length List:public static final <T> List<T> asList(final T[] array) {
       return new AbstractList<T>() {
          public T get(int index) {
             return array[index];
          public T set(int index, T value) {
             T oldValue = get(index);
             array[index] = value;
             return oldValue;
          public int size() {
             return array.length;
    }In fact it's highly likely that Arrays.asList() does something very similar to the above.
    Given all the neat things that a List can do, it's a pretty powerful bit of code, and only possible because of the existence of AbstractList.
    HIH
    Winston

  • Why use an interface?

    Hey everybody,
    I posted a message in another thread about why to use an abstract class. I have another question and again I am not asking how but why and when. But this time about interfaces. Why would I need to write one? Any example that is not too technical would be great!
    I have read a lot about interfaces but mostly it explains how to write one and not when and why to use them.
    Thanks in advance for your help!

    807479 wrote:
    So my question is basically how does implementing an interface help if there is no code in any of the methods?Because it says to anyone who wants to know "this class fulfills the contract for <tt>x</tt>", where <tt>x</tt> is the behaviour (methods) associated with the interface.
    Furthermore, in the same way that the language allows you to use a superclass as a type, it also allows you to use interfaces as types.
    I presume you're aware that an object can be passed to any method that takes its superclass; well, it can also be passed to any method that takes an interface that it implements.
    <tt>String</tt>, for example, implements <tt>Comparable</tt> (a good real-world interface to get familiar with, BTW), so a <tt>String</tt> object can be passed to either of the following methods:public String append(String s)...
    public int compareWith(Comparable c)...Now, how does that help you? Suppose you write a program that uses a <tt>List</tt>. A common beginner's mistake is to type everything to the nth degree, viz:ArrayList<String> myList = new ArrayList<String>();and then write methods in the same way:public void addSomeStrings(ArrayList<String> list,
       String... items) {.....but, while it will work, it's quite brittle.
    Suppose you decide later on that an <tt>ArrayList</tt> isn't the best way to store your Strings ... what do you do? You have to refactor every bit of code that took an <tt>ArrayList</tt> to now take a new type of List (eg, a <tt>LinkedList</tt>).
    Suppose instead that you wrote your program as follows:List<String> myList = new ArrayList<String>();and then your methods (hopefully ALL of them) as:public void addSomeStrings(List<String> list,
       String... items) {..... Now to change the program to use a <tt>LinkedList</tt>, the ONLY thing you have to change is:List<String> myList = new LinkedList<String>();and your program will work just fine.
    This is what a lot of the posts that talk about "programming to interfaces" are on about. It's a very good technique to get familiar with.
    HIH
    Winston

  • Why should I use an interface?

    I'm OK with how to use an interface but it's the why that I don't fully understand.
    For instance, in the following example:
    http://www.java2s.com/Code/Java/Language-Basics/InterfaceUsageExample.htm
    the interface method is called using tryout([actor's name]).
    Couldn't you just cut out the interface completely and use [actor's name].act()?
    An interface in this example just seems to add more lines of code but there must be an advantage I'm missing.
    Thanks in advance to anyone who can enlighten me.

    Here's the code you're referring to:
    interface Act {
      void act();
    class Actor1 implements Act {
      public void act() {
        System.out.println("To be, or not to be");
    class Actor2 implements Act {
      public void act() {
        System.out.println("Wherefore art thou Romeo?");
    public class TryOut {
      public static void main(String args[]) {
        Actor1 hamlet = new Actor1();
        Actor2 juliet = new Actor2();
        tryout(hamlet);
        tryout(juliet);
      private static void tryout(Act actor) {
        actor.act();
    }The example might be a bit misleading: Actor1 and Actor2 are declared as classes, but their behaviour is that of two particular characters (Hamlet and Juliette). So your question is a reasonable one.
    Sometimes this sort of example is given in terms of animals. Substitute speak for act and you get:
    interface Speaker {
      void speak();
    class Dog implements Speaker {
      public void speak() {
        System.out.println("woof");
      // other stuff like name, license number etc
    class Cat implements Speaker {
      public void act() {
        System.out.println("meeow!");
    public class TryOut {
      public static void main(String args[]) {
        List<Speaker> speakerList = new ArrayList<Speaker>();
        speakerList.add(new Cat());
        speakerList.add(new Dog());
        speakerList.add(new Cat());
        for(Speaker sp :speakerList) {
          tryout(sp); // or just sp.speak();
      private static void tryout(Speaker sp) {
        sp.act();
    }Now the instances of Cat and Dog share the behaviour as seen from the "outside" ie they both speak. But they are different types of things in as much as they implement that behaviour differently. Having a type, "Speaker", allows us to invoke this common behaviour without knowing or caring about the actual type of the particular instances.
    The example of having a collection of them is one time we might want to take advantage of this. When you have a List it has to be a list of something. In this case it is a list of Speaker instances.
    Edited by: pbrockway2 on Dec 17, 2008 6:43 PM
    d@mn cut-n-paste

  • I like to know the table name where all the Interface name ( Data Type and

    Dear Friends,
    I like to know the table name where all the Interface name ( Data Type and Message Type in IR ) is stored.
    Thanks.

    Hi,
    Please find the repository API’s in the SE24 class builder that can be used for accessing repository objects from the ABAP stack of SAP XI. Check CL_SRAPI* in the SE24 transactions for digging further.
    location of interface objects
    CL_SRAPI_DATA_TYPE---data type
    CL_SRAPI_DATA_TYPE_ENH---data type enhancement
    CL_SRAPI_FAULT_MESSAEG_TYPE--fault message type
    CL_SRAPI_MESSAGE_TYPE--message type
    CL_SRAPI_INTEGRATION_SCENARIO--integration scenario
    have a look at the table SXMSPMAST, SXMSCLUP & SXMSCLUR
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/4fbe7b8e-0a01-0010-b69b-b7e717378f22#search=%22SXMSPMAST%20%2B%20XI%22
    That document has references to lot of tables maybe it can be of use to u.
    Look at the below thread for SXMB_MONI tables and Function module:
    In Which Database Table the Messages are Stored in XI
    Message Monitoring  --> corresponding tables?
    Edited by: Dharamveer Gaur on Oct 8, 2008 10:40 AM

  • Change volume and Balance of speaker using Clip interface

    Hello,
    I am playing more than one Clip simulteniously. I want to change the volume and balance of individual Clip so that they have individual effect on speaker. I mean, if there are two clip then one should have high sound and other have low like that.
    Any help would be appreciated.
    Thanks in Advance.

    Hello,
    I play a sound using Clip interface in Java Sound. i am able to get FloatControl.Type.MASTER_GAIN) control but not FloatControl.Type.PAN)
    I have written a code like this,
    FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.PAN);
    Any help would be appreciated.
    * Thanks In advance*

  • Editing the Customer Address using Open Interface

    Hi All,
    The requirement is to edit the address details(postal codes) of the customer using Open Interface and not the APIs.
    They are insisting on using open interface as the Vertex validation(Taxation rules) is taken care only by Open Interface.
    Will need help on this.Kindly advice.

    Please refer the following whitepaper
    https://metalink2.oracle.com/cgi-bin/cr/getfile.cgi?p_attid=67196.1:1
    Thanks,
    Anil

  • Populating the Addressee field using Customer Interface program

    Hello All,
    Can any body tell me how to populate the "Addressee" column in the HZ_Party_Sites table using Customer Interface Program. Which field should be populated in RA_Customers_Interface_All table inorder to populate the "Addressee" field.
    Thank you,
    Vijay

    You can post this thread in this
    Customers as well.
    Thanks
    GM

Maybe you are looking for

  • Backupping system failed

    Urgent help needed. Hello, This evening I tried to backup the files in Recovery Q file. In a 4.7GB DVD. I started with a simple click on the red icon at Computer. It was a long wait, but finally i got something that the first part was succesfully suc

  • Error while installing Healthcare Library of SOA 11.1.1.7

    Hi Anuj, I have tried to install Healthcare library of SOA 11.1.1.7(PS6). For installation i have followed the following link given posted by you. http://www.oracle.com/technetwork/middleware/healthcare/downloads/index.html I am unable to install Hea

  • Search in PDF

    Hi all, My Client requirement is to do a PDF search (non-english) in the Search module of his e-learning website. When i try to extract the contents of PDF for indexing, some of the characters are neglected during extraction (empty spaces in that are

  • How do I delet storeg on iCloud

    I Can't delet my storeg on the cloud and now i can't update eny of my apps

  • Ipod on Iphone onlys plays parts

    I have an iphone 3g and the ipod part, it only plays a few secounds of a song. any idea why?