Nested interfaces and abstract methods

Consider the following design:
interface ZIF_INTERFACE_A.
  methods METHOD_A.
endinterface.
interface ZIF_INTERFACE_B.
  interfaces ZIF_INTERFACE_A.
  methods METHOD_B.
endinterface.
class CLASS_A_B definition abstract.
public section.
  interfaces ZIF_INTERFACE_B
    abstract methods METHOD_B.
  interfaces ZIF_INTERFACE_A
    abstract methods METHOD_A.
  methods METHOD_C.
endclass.
class CLASS_A_B implementation.
  method METHOD_C.
  endmethod.
endclass.
When trying to implement this design, the syntax check is giving me an error:
The method "METHOD_A" was declared as not ABSTRACT in a previous INTERFACES statement.
If I implement the design with Java (either using a public nested interface, or using interface inheritance) there is no problem declaring both the methods METHOD_A and METHOD_B as abstract in the CLASS_A_B class.
So it seems to me this might be a bug in the ABAP Objects implementation. Or perhaps I am missing something else here? Does anyone have any suggestions?

Hello,
Nested interfaces
When you include an IF in another IF both of them will exist on the same level, there is no concept of hierarchy. So when you add interface ZIF_B in the implementing class ZCL_A_B, the interface ZIF_A is also "included" in the relationship with the class ZCL_A_B implicitly.
Just try to activate the code below & you'll get the error: "Implementation missing for method zif_interface_a~method_a":
CLASS class_a_b DEFINITION ABSTRACT.
  PUBLIC SECTION.
*    INTERFACES zif_interface_a
*      ABSTRACT METHODS method_a.
    INTERFACES zif_interface_b
      ABSTRACT METHODS: method_b.
    METHODS method_c.
ENDCLASS.                    "CLASS_A_B DEFINITION
CLASS class_a_b DEFINITION ABSTRACT.
  PUBLIC SECTION.
    INTERFACES zif_interface_b
      ABSTRACT METHODS method_b.
    INTERFACES zif_interface_a
      ABSTRACT METHODS method_a.
    METHODS method_c.
ENDCLASS.                    "CLASS_A_B DEFINITION
So when the compiler is trying to compile your code it encounter implementation of ZIF_INTERFACE_B it finds that the "included interface" method ZIF_INTERFACE_Amethod_a is not abstract. So when you declare ZIF_INTERFACE_Amethod_a as "abstract" in the next line the compiler throws this error.
So you need to define ZIF_INTERFACE_A~method_a as abstract, before defining ZIF_INTERFACE_B. Like this:
CLASS class_a_b DEFINITION ABSTRACT.
  PUBLIC SECTION.
    INTERFACES zif_interface_a
      ABSTRACT METHODS method_a.
    INTERFACES zif_interface_b
      ABSTRACT METHODS method_b.
    METHODS method_c.
ENDCLASS.                    "CLASS_A_B DEFINITION
In this case the compiler treats method_a as abstract while checking ZIF_INTERFACE_B. Hence it doesn't throw any error.
Hope i'm clear.
BR,
Suhas
PS: Whenever i face any problem while creating local classes, i create a dummy class in the class builder to check

Similar Messages

  • Help with interface and abstract

    Hi all
    what is the difference between an interface and an abstract class??

    Suppose if you want to implement all the methods we usually use the interface. if you define a method in the interface you must provide the implementation for this interface in the implementation class.
    In case of abstract, we can have both the abstract and non -abstract methods. Means abstract class can have the methods with the implementations defined in that class and abstract methods which needs to be implemented for the sub classes.

  • Interface and Abstract class difference

    An interface can be used in such a way that we don't know the class of object assigned to a reference of that interface type until runtime. Can we use the abstract class in a similar way too?
    The difference between an abstract class and interface can be listed as
    1. Interface can not have implementation of any method
    2. The usage of interface and class is one other difference
    3. What other differences we have?

    Yes an abstract class can be used in a similar way. The main issue with an abstract class is that you extend it and you can only extend one class so that can be a huge limitation that an interface does not give you.
    Here's another one that is often overlooked: use both.
    public abstract class SomeBaseClass implements Runnable {
      public abstract void someAbstractMethod();
      public void someMethodWithADefaultImplementation(){
        System.out.println("Hello!");
    }Any class that extends SomeBaseClass (and is not abstract) will need to implement the run() method of the Runnable interface.

  • Interfaces and abstract classes

    can anyone pls tell me where exactly an abstract class is used and where exactly an interface is to be used.
    i think the main difference between an abstract class and an interface is that an interface will have all the abstract methods whereas an abstract class can have one or more abstract methods--- if i am not wrong.
    anything to add? -- pls let me know on this....
    and also how they might be useful for us....

    Inheritance is the most popular feature of the OOP. By organising classes into class hierachy it gives an extra dimension to the encapsulation of abstract data types becauase it enables classes to inherit attributes/methods from other classes.
    There are two complementary roles of inheritance in OOP application.
    1. Specialisation: Extending the functionality of an existing class.
    2. Generalisation: Sharing commonality between two or more classes.
    So adding functionality by extending what exists at each level to create more specialized classes. This would create a hierarchy and would be helpful even later on in maintenance.
    Now when to have an abstarct class and when an interface. An interface just defines the basic functionality to be implemented by all the subclasses, though the way they are implemented may be different. e.g an interfaca animal can have all those functionalities common to all animals in basics but different in implementation. e.g all animals walk however some walk on two legs and some on four. All animals can see but they might have a different colour spectrum visible. So all such methods general but common can be in an interface.
    Abstract classes come into play at a more defined level e.g in an abstract class human though walk would be the same so implemented there and then but talking can be left abstract since there may be different languages involved.
    For more details refer to a good OOP book.

  • Nested Classes and Static Methods

    I was perusing the Java Tutorials on Nested Classes and I came across this...
    [http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
    I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
    Static Nested Classes
    As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
    Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Superclass and subclass and abstract method

    Hi all,
    I am a little bit confused about abstract methods.
    I define a superclass without abstract keyword and an abstract method inside the superclass. Then I write a subclass to extend the superclass.
    When I compile the source code I get error. It looks like I can't initiate an instance from the supercalss and/or subclass. If I put abstract key word in the superclass definition there is no problem at all. So my question: does abstract method needed to be defined in an abstract superclass only?
    Thank for you input.

    Abstract methods can only be declared in an abstract class.

  • Interface and Abstraction

    hi,
    i want to know in which scenario of the project we can go for interface or abstraction, can anybody tell me the scenario with example

    http://faq.javaranch.com/view?InterfaceVsAbstractClass

  • Interfaces and class methods

    I want to implement an interface (to set common methods), but I want a method to be a class method of the concrete subclasses. Is there any way to do this? I cannot declare methods static in an interface. If I declare the method static in the concrete subclass this generates a compiler error.

    No I tried that! You cannot declare a class abstract and then declare the method abstract and static!
    I can create a method in the abstract class that is static and this can then be overwritten in the subclass, but there is no guarantee that the subclass implementer overwrites this method.
    Perhaps a redesign is in order. I don't think what I am trying to do is so obscure an interface means that you can be sure that the method is implemented, but this method is crying out to be a static method!

  • Interface and abstract class

    why we have constructor for abstract class and not for interface,

    When you call a constructor of a class which is extended by abstract class. It runs first the abstract class constructor and then child class constructor and initialize the member variables.
    while interface has no variable all final data so interface is no need to implement a constructor.
    Regards,

  • How to use interface and abstract class in the real time sennario ?

    how to validate password and reenter password fields in the struts through the xml files?

    Here is a modified dealForm.jsp that merges the 2 steps - both symbol submission and Yahoo convert is done by it. Play with it and add your DB code to it:
    <html>
    <head><title>IPIB Database Selection</title></head>
    <body bgcolor="#DFDFFF">
    <H1><CENTER>IPIB Database Selection</CENTER></H1>
    <font size=4>
    <%@ page language="java" %>
    <%@ page import="java.net.*,java.io.*,java.util.*" %>
    <%
    String symbol = request.getParameter("symbol");
    if (symbol != null) {
    String urlString = "http://finance.yahoo.com/download/javasoft.beans?SYMBOLS=" + symbol + "&format=ab";
    try {
    URL url = new URL(urlString);
    URLConnection con = url.openConnection();
    InputStream is = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();
    StringTokenizer tokenizer = new StringTokenizer(line,",");
    String name = tokenizer.nextToken();
    name = name.substring(1, name.length()-2);
    String price = tokenizer.nextToken();
    price = price.substring(1, price.length()-2);
    %>
    <p>
    Original line from yahoo <%= line %>
    </p> <p>
    Name: <%= name %>
    </p> <p>
    Price: <%= price %>
    </p> <p>
    Pub DB processing code from dealLoad.jsp here
    </p>
    <%
    } catch (IOException exception) {
    System.err.println("IOException: " + exception);
    } else { %>
    <form action="dealForm.jsp"method="GET">
    <p>Enter Symbol: <input size="20" name="symbol">
    <inputtype="submit" value="Submit">
    </p></form>
    <% } %>
    </font>
    </body>
    </html>

  • Interfaces and static methods

    Hi All,
    Does anyone know why you can't declare static methods in an interface? Is there a way round this problem?
    Cheers...

    But this won't:public class StijnsClass
      public static void aMethod()
        System.out.println("StijnsClass.aMethod()");
      public static void main(String[] arg)
        StijnsClass stijnsInstance = new StijnsSubClass();
        stijnsInstance.aMethod();
        System.out.println("Nothing else to say, here?");
    class StijnsSubClass extends StijnsClass
      public static void aMethod()
        System.out.println("StijnsSubClass.aMethod()");
        super.aMethod(); // Wrong!!!
    }You will get:
    "StijnsClass.java:21: non-static variable super cannot be referenced from a static context".
    If you remove static from the subclass method definition, you will get:
    "StijnsClass.java:18: aMethod() in StijnsSubClass cannot override aMethod() in StijnsClass; overridden method is static"
    That's the point. You aren't extending the method; you are only hiding it. To make it work, both methods must be instance methods, ergo, static methods cannot be extended.

  • Should @Override apply to implementation of interface/abstract methods?

    To me this is a minor but irritating incompatibility between Java 5 and 6. In 5 the @Override annotation only applied when an actual concrete method was overridden. In 6 it also applies when an interface or abstract method is implemented.
    To my mind only the first case is actually overriding. Further the purpose of the @Override, AFAIKS, is to catch errors where you accidentally override a method, or write a method which you expect to override another, but get the signature wrong.
    This kind of error isn't going to happen on implementing a method because you will get a real syntax error.
    If we were going to use annotations to guarantee implementation it should be @Implements

    sabre150 wrote:
    masijade. wrote:
    Having spend some time recently changing from extending abstract classes to implementing interfaces I would hate to have two different annotations!It would be annoying, yes, in that case, but it would still be more "technically" correct to have a different tag. And, if we are going to insist that "newbies" here at least attempt to adhere to standards/procedures/whatever, we should be willing to do the same. ;-)It would be more "technically" correct to have an 'override' key word in the same way as in C# . The annotation approach is used to make up for a deficiency in the language specification. If one applies the KISS principle or the 'principle of least surprise' then just having one annotation makes sense.Okay then, we agree to disagree. But getting even farther away in the "use" of the term as opposed to the "definition" of the term isn't helping to make up for the deficiency in the language.
    Of course, in the practical sense it is better to have one as it is, then, least likely to "break" in a backwards compatability sense (even when it only applies to compilation and not execution).

  • Outbound and Abstract Sync message Interface difference

    Hi Experts,
    Is there any difference between the input and output messagetype for Outbound/Inbound Synch Message Interface and Abstract Sync Message Interface.
    Do we  need to mention the same input and output messagetype for both outbound and Abstract or it should be otherway around?
    Regards
    Sara

    ---Is there any difference between the input and output messagetype for Outbound/Inbound Synch Message Interface and Abstract Sync Message Interface.
    No there is not. U can select any message type irrespective of the type of message interface.
    ---Do we need to mention the same input and output messagetype for both outbound and Abstract or it should be otherway around?
    Yes. As per ur requirement u can specify the same.
    Regards,
    Prateek

  • Interfaces vs abstract classes

    hi,
    i have some kind of general idea about interfaces and abstract classes.but what are the situations that are most suitable for use interfaces and abstract classes..if u have any idea pls help me
    thanx and best regards,
    Kelum

    BigDaddyLoveHandles wrote:
    Reason for using interfaces #17: dynamic proxies.
    import java.lang.reflect.*;
    interface Fooable {
    void f();
    void g(int x);
    class Foo implements Fooable {
    public void f(){ System.out.println("Foo.f()"); }
    public void g(int x){ System.out.format("Foo.g(%d)", x); }
    public class ProxyExample implements InvocationHandler {
    private Fooable target = new Foo();
    public static void main(String[] args) {
    Fooable fooable = (Fooable) Proxy.newProxyInstance(
    Fooable.class.getClassLoader(),
    new Class[] { Fooable.class },
    new ProxyExample());
    fooable.f();
    fooable.g(17);
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    System.out.println("Invoking: " + method.getName());
    return method.invoke(target, args);
    <cat position_relative_to_pigeons="among">
    Although libraries like ASM or CGLIB allow you to dynamically proxy classes, too
    </cat>

  • JSF annotations on interface or abstract class

    Hello,
    Can we use JSF 2 annotations like @ManagedBeans or @SessionScoped for interfaces and abstract classes? I mean, will it works if I implement an interface which declares some annotation(s) and the managed bean class itself doesn't have annotations?
    Thanks a lot!
    Oleg.

    Okey, an example:
    @ManagedBean
    public abstract class MyAbstractClass {
    public class MyClass extends MyAbstractClass {
    Does it work if I access MyClass by ValueExpression #{myAbstractClass} ? Will be MyClass automatically annotated with @ManagedBean?
    Best regards.
    Oleg.

Maybe you are looking for

  • Convert digital waveform to array

    Hello, I posted a problem before Christmas regarding data acquisition and accessing the hardware buffer on a 6562 card. I managed to figure out that problem but now I'm stuck when I try manipulating the data I obtain. (The original problem can be see

  • BSOD caused by e22win7x64.sys

    Hey all, recently I have some issues related with e22win7x64.sys. I believe this BSOD is caused by Killer network manager. I have checked all possible solutions like uninstall Killer network, and only install the drivers. Unfortunately, it doesn't he

  • Imac 2009  Intel Processor - Wired Mouse Question

    In a nutshell, since I have purchased my imac my wired mac mouse has been acting strangely where my desktop screen suddenly fills up with expose type screens. eg i go into preferences mouse settings then suddenly i get a pinkish background and other

  • Import/Export vs. Load/SaveData

    I am trying to figure out the difference between Import and Export Data and Save/LoadData. I notice that Import export allows me to choose a file name each time I Export it, and Load/Save just lets me complete the action without the additional naming

  • Opening CS5 projects in CS4?

    Im still using AE CS4 and I'm trying to work on a project with someone using CS5, but I'm unable to open his .aep. Is there a way for him to save his CS5 project so that it can CS4 can open it?