I want to have an abstract class Server with an abstract method called Initialize that passes a reference to IConnection, by reference. From there, a class deriving from this should be able to essentially specialize the IConnection object with its implementation of Initialize. This is fine except that I want to also have two abstract methods: DataSent and DataReceived and I want to use the specialized type in their signature, perhaps through generics.
Something like this is what I want:
public override void Initialize(ref IConnection connection)
{
connection = new MySpecialConnection(connection);
}
public override void DataSent(MySpecialConnection connection, byte[] data)
{
}
public override void DataReceived(MySpecialConnection connection, byte[] data)
{
}
Is there an easy way to do this? I’ve been playing around with generics for the better portion of a few days and nobody I have spoken with online has been able to come up with a solution.
For those of you who think you see the solution: when I tried doing this with generics it was pretty complex and due to variance problems it was just not wanting to work right.
Why not just this?