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

Similar Messages

  • Communication between thread in the same process using file interface.

    Hi,
    I am developing  driver and i need to communicate between two thread.
    >can anyone guide me on implementing communication between two thread in the same process using File Interface. First thread will be driver and second will be application.I need to send IOCTL like commands using File interface ie is WriteFile(),ReadFile()
    from Host process to driver through file-interface(which run's in driver context).Host process should not be blocked for the duration of the driver to process the command.
    >File-interface will run in driver context and it will be responsible to receive command from application and pass it to the driver.
    what are the complexity introduced?
    >Can anyone also give me the link/reference to get more information on this topic?
    >How to replace IOCTL command's for instance baud _rate change command with a file interface for example with IRP.

    Here  is the detailed query:
    Hardware Abstraction Layer will interact with Driver(Both will be running in complete different process) .there is a IOCTL for command and  File interface for read and write.
    My requirement is:
    Both should run in the same process so HAL will run as one thread and driver as another thread in the same process .I don't want HAL to wait for completion of request and also i don't want driver to be blocked .
    We are planning to use a File Interface for communication between Hardware abstraction layer and Driver
    HAL will send the command or read/write operation to a file interface and driver will get the command or read/write request from the File interface
    There is a flexibility to change Hardware Abstraction layer and also the Driver
    Is it possible to use IOCTL between two thread under same process? if not what other options do we have.
    Can we use File interface to  send command (like IOCTL) between two thread?

  • Newbie question on using an Interface

    I am something of an advanced beginner, one of those guys who can write simple stuff and maintain code but always have a bunch of questions.
    I am able to use an interface in a simple example shown below:
    import java.util.*;
    import java.text.*;
    public class ClassTest
    public static void main(String args[])
    new ClassTest();
    ClassTest()
    IfcPrintClass dao=null;
    try{ dao = (IfcPrintClass)Class.forName("ThatPrintClass").newInstance();
    }catch (Exception e) {};
    System.out.println(dao.PrintTheClass());
    try{ dao = (IfcPrintClass)Class.forName("ThisPrintClass").newInstance();
    }catch (Exception e) {};
    System.out.println(dao.PrintTheClass());
    } //end ClassTest
    What I am wondering is how do I instantiate (hope that's the right terminology) a class via an interface when the class has parameters? The API and other examples, at least ones I've seen, don't spell this out.
    I have to maintain a piece of code (ie, I didn't write it) with a class defined below. We need to create an interface for this class to implement so we can re-use this and similarly named classes for other projects. For example, the below listed class is to handle our SQL I/O, but naturally the db handling will varying from project to project. I want to be able to dynamically load a class within my code and pass the class name and directory into the package via ARGS (again, hope I'm using terminology correctly). I am trying to figure out how to adapt my above example to the below class instantiation, but cannot figure out how to pass the parameter along with it. I do know how to create an interface. In the below example "errorModule" is another class that handles our error and information logging, but is abstract enough that it will not change project to project. The "insertLoader" method is a sample method that the DAOLoader class will do, as is "isConnected".
    dao = new DAOLoader(errorModule);
    if(dao == null || !dao.isConnected()) //connection failed
    // handle this error
    else
    dbAlreadyFailed = false;
    if(firstDatabaseConnection)
    dao.insertLoader();
    thanks in advance, and hope you can help.

    As requested, here is the code I posted using code tags,and I'll do this in the future:
    ClassTest.java:
    import java.util.*;
    import java.text.*;
    public class ClassTest
    public static void main(String args[])
    new ClassTest();
    ClassTest()
    IfcPrintClass dao=null;
    try{ dao = (IfcPrintClass)Class.forName("ThatPrintClass").newInstance();
    }catch (Exception e) {};
    System.out.println(dao.PrintTheClass());
    try{ dao = (IfcPrintClass)Class.forName("ThisPrintClass").newInstance();
    }catch (Exception e) {};
    System.out.println(dao.PrintTheClass());
    } //end ClassTestMy actual code:
    dao = new DAOLoader(errorModule);
    if(dao == null || !dao.isConnected()) //connection failed
    // handle this error
    else
    dbAlreadyFailed = false;
    if(firstDatabaseConnection)
    dao.insertLoader();
    }IfcPrintClass.java:
    public interface IfcPrintClass
    String PrintTheClass();
    }ThatPrintClass.java:
    public class ThatPrintClass implements IfcPrintClass
    public String PrintTheClass()
    return "That";
    }Then I have a class ThisPrintClass:
    public class ThisPrintClass implements IfcPrintClass
    public String PrintTheClass()
    return "This";
    }

  • 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 java support multiple inheritance by the use of interface.

    As per my understanding, Interface is just having the signatures of the methods not the implementation.
    So How java support multiple inheritance by the use of interface?
    Answer 1: we can institate interface reference by its implemented
    class.
              ����� interface inf...
              ����� class aa implements inf..
              ����� class bb implements inf....
               Now, inf i = new aa();
               inf i = new bb();
    Answer 2: We can extends as many interface as we want in the
    single
               interface.
               i.e. interface infFirst....
               interface infSecond....
               interface infThird....
               Now ,
               interface ingMulti extends infFrist, infThird...
    By above two answers its not prity clear as per the multiple inheritance in C or C++.
               i.e.
               class first{
               method abc();....}
               class second{
               method bbc()......}
               class multi::first::second{
               we can call to abc();.....as well as bbc();
    -Please give your important suggstion on the same.(Hope I explain it well.)
    -Jeff

    The keyword implement is used only for interfaces not
    for abstract class. If i am wrong correct me.I believe your right, but I will double check.
    As for the multiple inheritence think about the following code:
    class Animal {
        //  Animal generic stuff in this class
    interface Eat {
        //  Generic stuff that models eating behavior
    interface Runs {
        //  generic methods that model running behavior
    public class Horse extends Animal implements Eat, Runs {
        //  Stuff specific to a horse
    }The Animal class is generic but has stuff in it common to all animals.
    The Eat interface models behavior that is generic to eating, all living things have to eat something to survive. Herbavore are different from carnivores.
    The Runs interface models generic behavior to running, such as speed. A cheeta definately runs faster than a human.
    This brings us to the Horse class. It extends the Animal class because it "is-a" animal, and it implements the eat and runs interface because they are behaviors a horse has.
    I hope that helps.
    Extending an abstract class is the same as extending a regular class with the exception you MUST override all abstract methods in the abstract class. Thats not too difficult but I believe when designing classes, designing an abstract can be more diffecult than modeling the base class, and generic behaviors in interfaces. JMO.
    JJ

  • Unusual use of interface defining static factory class with getInstance

    This question is prompted by a recent New to Java forum question ask about the differences between Interfaces and Abstract classes. Of course one of the standard things mentioned is that interfaces cannot actually implement a method.
    One of my past clients, one of the 500 group, uses interfaces as class factories. The interface defines a pubic static class with a public static method, getInstance, that is called to generate instances of a class that implements the interface.
    This architecture was very object-oriented, made good use of polymorphism and worked very well. But I haven't seen this architecture used anywhere else and it seemed a little convoluted.
    Here is a 'pseudo' version of the basic interface template and use
    -- interface that defines public static factory class and getInstance method
    public interface abc {
        public static class FactoryClass
            public static abc getInstance ()
                return (abc) FactoryGenerator(new abcImpl(), abc.class);
    -- call of interface factory to create an instance
    abc myABC = abc.Factory.getInstance();1. Each main functional area ('abc' in the above) has its own interface factory
    2. Each main functional area has its own implementation class for that interface
    3. There is one generator (FactoryGenerator) that uses the interface class ('abc.class') to determine which implementation class to instantiate and return. The generator class can be configured at startup to control the actual class to return for any given interface.
    I should mention that the people that designed this entire architecture were not novices. They wrote some very sophisticated multi-threaded code that rarely had problems, was high performance and was easy to extend to add new functionality (interfaces and implementing classes) - pretty much plug-n-play with few, if any, side-effects that affected existing modules.
    Is this a best-practices method of designing factory classes and methods? Please provide any comments about the use of an architecture like this.

    Thanks for the feedback.
    >
    I don't see how 'the generator class can be configured at startup to control the actual class to return for any given interface' can possibly be true given this pseudo-code.
    >
    I can see why that isn't clear just from what is posted.
    The way it was explained to me at the time is that the interface uses standard naming conventions and acts like a template to make it easy to clone for new modules: just change 'abc' to 'def' in three places and write a new 'defImpl' class that extends the interface and the new interface and class can just 'plug in' to the framework.
    The new 'defImpl' class established the baseline functionality that must be supported. This line
    return (abc) FactoryGenerator(new abcImpl(), abc.class);uses the initial version of the new class that was defined, 'abcImpl()', when calling the FactoryGenerator and it acted as a 'minimum version supported'. The generator class could use configuration information, if provided, to provide a newer class version that would extend this default class. Their reasoning was that this allowed the framework to use multiple versions of the class as needed when bugs got fixed or new functionality was introduced.
    So the initial objects would be an interface 'abc' and a class 'abcImpl'. Then the next version (bug fixes or enhancements) would be introduced by creating a new class, perhaps 'abcImpl_version2'. A configuration parameter could be passed giving 'abcImpl' as the base class to expect in the FactoryGenerator call and the generator would actually create an instance of 'abcImpl_version2' or any other class that extended 'abcImpl'.
    It certainly go the job done. You could use multiple versions of the class for different environments as you worked new functionality from DEV, TEST, QA and PRODUCTION environments without changing the basic framework.
    I've never seen any Java 'pattern' that looks like that or any pattern where an interface contained a class. It seemed really convoluted to me and seems like the 'versioning' aspect of it could have been accomplished in a more straightforward manner.
    Thanks for the feedback. If you wouldn't mind expanding a bit on one comment you made then I will mark this ANSWERED and put it to rest.
    >
    I don't mind interfaces containing classes per se when necessary
    >
    I have never seen this except at this one site. Would you relate any info about where you have seen or used this or when it might be necessary?

  • 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.

  • Doubt about interface & abstract

    Hai everybody,
    I am new java technology. I need clear discribtion about interface & abstract.
    Please give some examples and differentiate it.
    i awaiting for your reply
    by
    azhar

    Even Wikipedia has info about this:
    http://en.wikipedia.org/wiki/Interface_%28Java%29
    http://en.wikipedia.org/wiki/Class_%28computer_science
    %29#Abstract_and_concrete_classeswhenever someone asks this question, they don't really want to read about it, they just want someone to tell them the secret rules about when to use an interface and when to use an abstract class. but we're not telling :-)

  • Interface & abstract class

    1>whats the basic difference between an interface and an abstract class?
    when should one be using an interface or an abstract class?
    2>whats the difference between method overriding and method overlaoding?
    does both of them has any relation with the instance of te class implementing them?

    http://www.google.com/search?q=java+interface+%22abstract+class%22
    http://www.google.com/search?q=java+method+overloading+overriding

  • 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

  • Can i use one interface to load data into 2 different tables

    Hi Folks,
    Can i use one interface to load data into 2 different tables(same schema or different schemas) from one source table with same structure ?
    Please give me advice
    Thanks
    Raj
    Edited by: user11410176 on Oct 21, 2009 9:55 AM

    Hi Lucky,
    Thanks for your reply,
    What iam trying is ...Iam trying to load the data from legacy tables(3) into oracle staging tables.But i need to load the same source data into two staging tables(these staging tables are in two different schemas)
    can i load this source data into two staging tables by using single standard interface(some business logic is there)
    If i can then give me some suggestion how to do that
    Thanks in advance
    Raj

  • How to use multiple Interfaces for the same BS?

    Hi @ ,
    Is it possible to have a scenarion where i am using multiple interfaces in the same BS based upon some conditional field in the message.
    I amnot able to get the solution I know with condition editor I can have multiple receivers but in my scenarion based upon message fiels i have to decide which BAPI to be used and wht mapping and then post it to the same System
    Any help will be highly rewarded
    Regards

    Hi-
    Yes it is possible you can use multimapping for mapping the interfaces.
    To know more about multimapping see
    http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm
    Some more helpful links
    /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible

  • Is there a way to run an existing PS-JS script using external interface

    I have several previously written Photoshop JS scripts which I'd like to run through buttons on PS panels, much like the example for the HelloWorld introduction. I assume that--using external interface--I'll somehow be able to fire off these script files. Is this a correct assumption?
    Thanks!

    Certainly, but not with external interface.
    Have a look at the cookbooks. There are examples of how to use the root host object to call directly into extendscript.

  • Error in using one interface in other

    Hello,
    I have two interfaces , interface1 & interface 2 . Interface 1 is a temp which is used by interface2 as a source.
    I'm trying to set the property "Use Temporary interface as derived table" but the check box is disabled and i cannot modify it. , Interface 1 has target temp table.
    Any advise ?
    In technology for oracle support derived table is already selected.
    thx

    Hi Matt
    I'm using the same FM but it's not working. Can you please share what data you are passing in the FM.
    After debugging I found that my confirmation is getting created but it's not getting saved.
    Please enlighten me.
    Thanks
    Ankit

Maybe you are looking for

  • Badi or Exit for changing subscreen in PO

    Hi Friends, Is there any Badi or Exit for changing shipping subscreen at item level for Purchase order.actualy my requirement is to supress all fields on shipping subscreen(Item Level) except route.How can I do it???? Please help...

  • What are the steps required in NWA and ID in order to enhance security of adapters in PI 7.31 Java Stack ?

    HI All, I am looking for steps need to follow for seurity and certificate management in PI 7.31 Java Stack. Could someone help me with the security and certificate management steps needs to follow for SOAP/RFC/MAIL adapter ? I looked at sap help link

  • Problem with SAP Logon

    Hi alls, I hope can some help me, I'm trying to connect to SAP via SAPLogon. I've tried to fix the problem but I don’t have success. SAP Logon Properties: Description:  NSP Application Server: localhost SAProuter-String: blank System-ID:        NSP S

  • SATA II Issues with 2004 G5

    I'm replacing the original 250 GB Hard Drive in my Single 1.8 GHz G5 (Purchased in 2004). I've narrowed down my choice to a 250 GB Western Digital Caviar SE16 or 500 GB Maxtor MaxLine Pro, which are both SATA II . I wanted to know if either drive wou

  • A way to display status all users in a LYNC group

    Lync Group Users status; Is there a way to create an easy to view folder  or window that would show all my Lync contacts in a group along with their current status as well as the green red etc. dot that indicates the same. I am currently doing this b