Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:45:22+00:00 2026-05-26T14:45:22+00:00

So I have made this simple interface: package{ public interface GraphADT{ function addNode(newNode:Node):Boolean; }

  • 0

So I have made this simple interface:

package{
    public interface GraphADT{
        function addNode(newNode:Node):Boolean;     
    }
}

I have also created a simple class Graph:

package{

    public class Graph implements GraphADT{

        protected var nodes:LinkedList;

        public function Graph(){
            nodes = new LinkedList();
        }

        public function addNode (newNode:Node):Boolean{
            return nodes.add(newNode);
        }
}

last but not least I have created another simple class AdjacancyListGraph:

package{
    public class AdjacancyListGraph extends Graph{

        public function AdjacancyListGraph(){
            super();
        }

        override public function addNode(newNode:AwareNode):Boolean{
            return nodes.add(newNode);
        }
}

Having this setup here is giving me errors, namely:

1144: Interface method addNode in namespace GraphADT is implemented with an incompatible signature in class AdjacancyListGraph.

Upon closer inspection it was apparent that AS3 doesn’t like the different parameter types from the different Graph classes newNode:Node from Graph , and newNode:AwareNode from AdjacancyListGraph

However I don’t understand why that would be a problem since AwareNode is a subClass of Node.

Is there any way I can make my code work, while keeping the integrity of the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:45:22+00:00Added an answer on May 26, 2026 at 2:45 pm

    Simple answer:

    If you don’t really, really need your ‘addNode()’ function to accept only an AwareNode, you can just change the parameter type to Node. Since AwareNode extends Node, you can pass in an AwareNode without problems. You could check for type correctness within the function body :

    subclass... {
        override public function addNode (node:Node ) : Boolean {
            if (node is AwareNode) return nodes.add(node);
            return false;
        }
    }
    

    Longer answer:

    I agree with @32bitkid that your are getting an error, because the parameter type defined for addNode() in your interface differs from the type in your subclass.

    However, the main problem at hand is that ActionScript generally does not allow function overloading (having more than one method of the same name, but with different parameters or return values), because each function is treated like a generic class member – the same way a variable is. You might call a function like this:

    myClass.addNode (node);
    

    but you might also call it like this:

    myClass["addNode"](node);
    

    Each member is stored by name – and you can always use that name to access it. Unfortunately, this means that you are only allowed to use each function name once within a class, regardless of how many parameters of which type it takes – nothing comes without a price: You gain flexibility in one regard, you lose some comfort in another.

    Hence, you are only allowed to override methods with the exact same signature – it’s a way to make you stick to what you decided upon when you wrote the base class. While you could obviously argue that this is a bad idea, and that it makes more sense to use overloading or allow different signatures in subclasses, there are some advantages to the way that AS handles functions, which will eventually help you solve your problem: You can use a type-checking function, or even pass one on as a parameter!

    Consider this:

    class... {
    
        protected function check (node:Node) : Boolean {
            return node is Node;
        }    
    
        public function addNode (node:Node) : Boolean {
            if (check(node)) return nodes.add(node);
            return false;
        }
    }
    

    In this example, you could override check (node:Node):

    subclass... {
        override protected function check (node:Node) : Boolean {
            return node is AwareNode;
        } 
    }
    

    and achieve the exact same effect you desired, without breaking the interface contract – except, in your example, the compiler would throw an error if you passed in the wrong type, while in this one, the mistake would only be visible at runtime (a false return value).

    You can also make this even more dynamic:

    class... {
        public function addNode (node:Node, check : Function ) : Boolean {
            if (check(node)) return nodes.add(node);
            return false;
        }
    }
    

    Note that this addNode function accepts a Function as a parameter, and that we call that function instead of a class method:

    var f:Function = function (node:Node) : Boolean {
        return node is AwareNode;
    }
    
    addNode (node, f);
    

    This would allow you to become very flexible with your implementation – you can even do plausibility checks in the anonymous function, such as verifying the node’s content. And you wouldn’t even have to extend your class, unless you were going to add other functionality than just type correctness.

    Having an interface will also allow you to create implementations that don’t inherit from the original base class – you can write a whole different class hierarchy, it only has to implement the interface, and all your previous code will remain valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi have made this function which is made to replicate an error that I
I have made a simple implementation of INotifyDataErrorInfo in a WPF 4.5 project. This
I have made a simple app to try a nut out the problem; this
OK, I was just fooling around in my spare time and have made this
I have made some progress with the DataList and UserControl this morning but I
Hi I made this site a while ago in my table days but have
This is a C++ class that I have made with n number of pointers.
This is my first winform app in .NET... I have made a couple of
Since I'm sure many people have different standard, I've made this post a community
I have a DLL made in C#, this DLL contains some clases like Creator.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.