Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualslicer4ever

Posted 05 April 2013 - 08:18 PM

I'm going over a design problem I have. basically I have a generic mesh class, that i feed some derived type that is of the base type Vertex. so, my problem is that I want the derived class to be able to pass information to the mesh class that is specific for it's implementation(it's pretty much the gpu formatting for that type).

something like this(note this is a sample to demonstrate the probelm, so try not to get caught up on the pointless-ness of the code):
public class abstract Foo{
  public abstract int GetX();
};

public class Foo_A : Foo{
  public override int GetX(){
     return 1;
  }
};

class class OtherClass<T> where T : Foo{

   public void GetTX(){
     return T.GetX();
   }
}
basically, the result of GetX doesn't need anything inside of the class, it just provides additional information for my OtherClass to access. One way I know i can make this work is to create an instance of T, in my particular case I have an array of T already, so i just call the method by accessing the first member of the array, but this feels incredibly dirty.

basically i need some type of static abstract class or const, since i'm going to be accessing OtherClass like so:
OtherClass<Foo_A> = new OtherClass<Foo_A>();
I feel their should be a way for me to access a static method in Foo_A through the OtherClass.

#1slicer4ever

Posted 05 April 2013 - 07:47 PM

I'm going over a design problem I have. basically I have a generic mesh class, that i feed some derived type that is of the base type Vertex. so, my problem is that I want the derived class to be able to pass information to the mesh class that is specific for it's implementation(it's pretty much the gpu formatting for that type).

something like this(note this is a sample to demonstrate the probelm, so try not to get caught up on the pointless-ness of the code):

public class abstract Foo{
  public abstract int GetX();
};

public class Foo_A : Foo{
  public override int GetX(){
     return 1;
  }
};

class class OtherClass<T> where T : Foo{

   public void GetTX(){
     return T.GetX();
   }
}
basically, the result of GetX doesn't need anything inside of the class, it just provides additional information for my OtherClass to access. One way I know i can make this work is to create an instance of T, in my particular case I have an array of T already, so i just call the method by accessing the first member of the array, but this feels incredibly dirty.

basically i need some type of static abstract class or const, since i'm going to be accessing OtherClass like so:
OtherClass<Foo_A> = new OtherClass<Foo_A>();
I feel their should be a way for me to declare a static method in Foo_A through the OtherClass.

PARTNERS