Reputation: 9273
I know I should use this much more widely, but our code only has a handful of Interfaces, so I'm a bit noob about them. Here's my problem. In file one I have this:
Friend Interface IDateRow
Property Name() As String
...
End Interface
Friend Interface IAmountRow
Property StartDate() As IDateRow
Property EndDate() As IDateRow
...
End Interface
In file 2 I have this:
Friend Class DateRow
Inherits DtaRow
Implements IDateRow
Friend Property Name() As String Implements IDateRow.Name
...
End Class
So far so good. Now...
Friend Class AmountRow
Inherits DtaRow
Implements IAmountRow
Friend Property StartDate() As DateRow Implements IAmountRow.StartDate
This will not work - it says:
'StartDate' cannot implement 'StartDate' because there is no matching property on interface 'IAmountRow'.
Am I correct in thinking this is because it returns a DateRow and not a IDateRow? DateRow implements IDateRow, so it seems like it should be legal.
I know I'm missing something dumb here...
Upvotes: 2
Views: 85
Reputation: 1796
Interface is an identity. Let's assume that IDateRow is placed in "A.dll" and DateRow that implemets it is in "B.dll". And lets assume that there is a function in A.dll that inputs an IDateRow instance. Since A.dll does not reference B.dll, it does not know what DateRow is. So it expects an instance that has a "Property StartDate() As IDateRow" not a DateRow.
Edit - My attempt to answer @MauryMarkowitz's comment:
I think an abstract class is what you want. I've written an example in c#, but I guess its similar in vb.
//A.dll -> has no reference
public abstract class Vehicle
{
public abstract double Mass();
public abstract double Force();
public double Acceleration()
{
return this.Force() / this.Mass();
}
}
public interface ICar
{
double MaxGroundSpeed();
}
public interface IPlane
{
double MaxAirSpeed();
}
//B.dll -> has a reference to A.dll
public class Ferrari360 : Vehicle, ICar
{
public override double Force()
{
return 400;
}
public override double Mass()
{
return 1350;
}
public virtual double MaxGroundSpeed()//Ferrari likes to make good cars, better, so this should be virtual.
{
return 282;
}
}
public class Ferrari360GT:Ferrari360
{
public override double Mass()
{
return 1100;
}
public override double MaxGroundSpeed()
{
return 300;
}
}
public class Concorde : Vehicle, IPlane
{
public override double Force()
{
throw new ClassifiedInformationException();
}
public override double Mass()
{
return 92080;
}
public double MaxAirSpeed()
{
return 2180;
}
}
public class DeLoreanTimeMachine : Vehicle, ICar, IPlane
{
public override double Force()
{
return 130;
}
public override double Mass()
{
return 1230;
}
public double MaxAirSpeed()
{
return 299792;
}
public double MaxGroundSpeed()
{
return 88;
}
}
An example use:
Ferrari360 greatCar = new Ferrari360();
Console.WriteLine(greatCar.Acceleration());
Upvotes: 0
Reputation: 82474
You must implement the property with the exact same type as the interface - so
Friend Property StartDate() As DateRow Implements IAmountRow.StartDate
Should be
Friend Property StartDate() As IDateRow Implements IAmountRow.StartDate
Upvotes: 3