Zagiel

Zagiel

  • NA
  • 7
  • 0

Help needed with design of a generic

Apr 9 2009 5:06 AM

I'm using something like these two classes:

class Binder1
{
 public void Add(Binder2 toAdd)
 {
  toAdd.Add(this);
  this.Add(toAdd);
 }
}
class Binder2
{
 void Add(Binder1 toAdd)
 {
  toAdd.Add(this);
  this.Add(toAdd);
 }
}

Instead of using a common parent class as the Add parameter I'd like to make use of generics, because it will be more convenient in the rest of the class functionality.

class Binder<T>
{
 public void Add(T toAdd)
 {
  toAdd.Add(this);
  this.Add(toAdd);
 }
}
class Binder1 : Binder<Binder2>
class Binder2 : Binder<Binder1>


but I don't know if that's possible. I'd very much appreciate help with design.
To me it seemed that single generic ID is not enough and that I can't go without

class Binder<T1, T2>

and of course to specify the the base to make Add() callable

where T1: Binder<T1, T2>
where T2: Binder<T2, T1>

but I'm hitting on T1 vs Binder<T1, T2> conversion problems.

I just probably make it too complicated and there is a much simpler way I don't see.
Is there?

Thanks very much for any suggestions.