2
Contributors
1
Reply
8
Views
1 Year
Discussion Span
Last Post by darkagn
0

I'm not sure what you mean by the first question, but I can answer the second.

An abstract function is one that defines a method signature without its body so that it can be overridden in any extending implementing class. I'm not sure which programming language you are using but I will demonstrate with a C# example.

// our base class must be abstract since it will contain an abstract function
public abstract class BaseClass
{
    // this function is abstract
    // it has a signature that says it takes no parameter but returns a boolean value
    public abstract bool foo();
}

// now for an implementing class that extends the base class
public class ImplementingClass : BaseClass
{
    // we override the abstract function from the base class
    public override bool foo()
    {
        return true;
    }
}

// let's do another implementation so we can show the real power later
public class AnotherImplementingClass : BaseClass
{
    // again, we override the abstract function
    public override bool foo()
    {
        return false;
    }
}

static void Main(string[] args)
{
    BaseClass first = new ImplementingClass();
    BaseClass second = new AnotherImplementingClass();
    BaseClass[] list = new BaseClass[] { first, second };

    foreach (BaseClass bc in list)
    {
        MessageBox.Show(bc.foo().toString()); // shows true the first time and false the second time
    }
}

Edited by darkagn

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.