[Mono-list] reusing interface implementation

Michał Ziemski rook at roo.k.pl
Tue May 27 10:51:43 EDT 2008


Hi!

I would go with something like:
abstract class TestBase {
    astract int x { get; }

  public void iF(){
    Console.WriteLine("x: "+x);
  }    
}

and then make A and B inherit from TestBase.

Alternatively you can do something like:

interface IX { int x { get; } }

class PlusTest<T> : ITest where T : IX {  
  private T val;
  public PlusTest(T val) { this.val = val; }
	
  public void iF(){
    Console.WriteLine("x: "+ val.x);
  }
}
 
Cheers!
Michał Ziemski


Mathias Tausig pisze:
> Hy!
>
> I have a class hierarchy which is usable as it is. But now I would like to
> extend it with an interface and create something like a parallel
> hierarchy. But as far as I can see, it is not possible to implement my
> interface only once.
> A simple example what I mean:
>
>
> public class A{
>        public A(){}
>        public virtual int x{
> 	 get{return 1;}
>        }
> }
> public class B:A{
>        public override int x{
> 	 get{return 2;}
>        }
> }
>
> public interface ITest{
>        void iF();
> }
>
> public class AplusInterface :A,ITest{
>   public void iF(){
>     Console.WriteLine("x: "+x);
>   }
> }
>
> And now I would like to have a class "BplusInterface" without having to
> implement the interface once again. Is that possible in C#?
>
> cheers
> Mathias
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>   



More information about the Mono-list mailing list