DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004

    Interfaces clash - what to do?

    I was never able to figure this out:

    A class implements two interfaces, IFace1 and IFace2, both of which have a method with the same name public void remove();

    However, the semantics of the two removes are different. IFace1 is supposed to remove an entry from queue1, while IFace2 from queue2.

    How do I solve this problem? With class name clashes, I can fully specify the namespace. Is there something similar for interface methods? I tried

    public void my.own.IFace1.remove() {...}
    public void john.made.IFace2.remove() {...}

    but it didn't compile Please help. Thanks

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    I hope you inherited this mess ... and didn't create it ...

    Have you tried addressing the class as an IFace1 object or an IFace2 object? How about casting it to an IFace1 or IFace2 object? Or design the method in the calling procedure to require an IFace1 or IFace2 object as an argument so that the object is automatically cast to the proper ADT?

    You wrote that the "semantics" of the two methods is different. Could you share the method signature which shows their difference? Could you modify the signature to be unique?

  3. #3
    Join Date
    Apr 2004
    well, half and half. IFace2 is inherited, but IFace1 is at my liberty. I don't think casting the object into an implementation of IFace1 or IFace2 would help because it still needs to call the remove() method, and the ambiguity is nontheless unavoidable.

    A clear solution I am having in mind is to name the remove() method in IFace1 to delete(). This is ugly, but unless there is a better way I can only stick with it.

  4. #4
    Join Date
    Dec 2004
    San Bernardino County, California
    why can't you just pass the queue you're interested in as a parameter, and use the one method? OR, if you must have two different methods because of how you are defining the methods, do you have different elements in your queues, so you can use the Generic signature to distinguish between the two IFace remove() methods (overload remove()). another thought is to create a hierarchy of the ADT of the elements being stored in the two queues, which are then populated by element types which inherit or implement the interface of the parent in the hierarchy.

    node ...... vertexNode

    you can then have queue1<VertexNode> and queue2<EdgeNode> and
    then your remove method can be remove(Node) which could be a queue of vertexNodes or of edgeNodes ....
    Last edited by nspils; 07-27-2007 at 01:03 AM.

Similar Threads

  1. Correct usage/method of Java Interfaces
    By AashuKapil in forum Java
    Replies: 4
    Last Post: 08-13-2007, 02:45 AM
  2. Interfaces in .net
    By vipinb in forum .NET
    Replies: 8
    Last Post: 05-25-2007, 05:46 AM
  3. Interfaces Inheriting from Interfaces
    By Larry Hunter in forum .NET
    Replies: 1
    Last Post: 01-26-2003, 11:45 PM
  4. Re: Interfaces Question
    By Robert Cullen in forum Java
    Replies: 0
    Last Post: 10-23-2001, 07:34 AM
  5. Dealing with interfaces.
    By Richard Burton in forum .NET
    Replies: 5
    Last Post: 02-25-2001, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.