Calling abstract method with no implementation

688 Views Asked by At

I m reading a Kudan for Unity exaple project (Kudan is a framework for AR)

in the file KudanTracker.cs they use a TrackerBase object called _trackerPlugin

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Kudan.AR
{
    [DisallowMultipleComponent]
    [RequireComponent(typeof(Camera))]
    [AddComponentMenu("Kudan AR/Kudan Tracker")]
    public class KudanTracker : MonoBehaviour
    {
        protected TrackerBase _trackerPlugin;
        public bool ArbiTrackIsTracking()
            {
                return _trackerPlugin.ArbiTrackIsTracking();
            }
    ...
}   

So i head over to TrackerBase.cs to see the implementation for ArbiTrackIsTracking() but all i find is this:

using UnityEngine;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Kudan.AR
{
    /// <summary>
    /// Base class for the tracker plugin.  This abstracts the native plugin for each operating system.
    /// </summary>
    public abstract class TrackerBase : ITracker
    {
         public abstract bool ArbiTrackIsTracking ();
         ...
    }
}

How is it possible to call a method that was never implemented?
where is the implementation hiding?
thank you

3

There are 3 best solutions below

0
On BEST ANSWER

This is perfectly normal.

Such behavior is normal, IF the class is properly instantiated with a non-abstract version of Trackerbase.

However, you don't provide the relevant instantiation code, so its impossible for me to verify if the code sample you provided is properly instantiated or not, without myself going to get that code.

Theoretically, the instantiation code might look like this:

//Constructor
public KudanTracker(TrackerImplementation track) {
    _trackerPlugin = track;
}

IF the code has proper instantiation, such as above, you're fine.

0
On

It's impossible to call an abstract method without any implementation.

As the comment for TrackerBase class says, Tracker classes are different for each OS, so look for TrackerWin.cs or something like that

0
On

They probably deal with it, like Microsoft dealt with the XmlReader:

You are using a derived class for the object you are using, but access it via its base class.

In the XmlReader it goes like this:

XmlReader reader = XmlReader.Create("something");

and then you can read every element within the xml-file via

reader.Read();

But as you can see, XmlReader.Read() isn't even implemented: Source

Instead, XmlReader.Create() creates an XmlTextReader which inherits from XmlReader and implements everything, especially how Read() is handled.

I guess they do the same in the plugin. See here in the API it states "Implemented in Tracker" KudanAR - Unity Plugin V1.4