Reducing the number of typed parameters

E

Efi

Hello,
I have the following two classes:
class Chunk<T,V1> {
V1 value;
T data;
}

class Feature<T,V2>{
V2 value;
T data}

I am writing a class that in essence transforms a Chunk into a
Feature.
class Transform<T,V1,V2> ...
public Feature<T,V2> transform (Chunk<T,V2> foo)...

Chunk and Feature has a common typed parameter(T) which I'm enforcing
when I'm declaring the Transform class.

I think that the transform class is just too confusing when I'm using
it with 3 typed parameters, I would like to reduce the number of typed
parameters and still have the same functionality.

At the beginning I thought using constraints i.e.
class Transform<U,V> where T : Chunk V : Feature

however in order to use it I need to add type to Chunk and Feature
i.e.
where T : Chunk<T,V1>
so it didn't help me.

What do you think, how can I do it?

Thank you,
Efi
 
J

Jon Skeet [C# MVP]

Efi said:
I have the following two classes:
class Chunk<T,V1> {
V1 value;
T data;
}

class Feature<T,V2>{
V2 value;
T data}

I am writing a class that in essence transforms a Chunk into a
Feature.
class Transform<T,V1,V2> ...
public Feature<T,V2> transform (Chunk<T,V2> foo)...

Chunk and Feature has a common typed parameter(T) which I'm enforcing
when I'm declaring the Transform class.

I think that the transform class is just too confusing when I'm using
it with 3 typed parameters, I would like to reduce the number of typed
parameters and still have the same functionality.

I don't see how that's possible. There are three types involved, so
assuming they could all me different, I fail to see how you can get rid
of one of them.
 
E

Efi

Jon כתב:
I don't see how that's possible. There are three types involved, so
assuming they could all me different, I fail to see how you can get rid
of one of them.

Thanks,
I agree with you, but the point here that one parameter is always the
same in Chunk and Feature - T.

T can have different types that is true.
I agree with you, I was hoping that there is some way to exploit this
common parameter.

Thanks anyway,
Efi
 
J

Jon Skeet [C# MVP]

Efi said:
Thanks,
I agree with you, but the point here that one parameter is always the
same in Chunk and Feature - T.

Which is why you have three parameters rather than 4. If the two Ts
could be different, it would have to be:

public Feature said:
T can have different types that is true.
I agree with you, I was hoping that there is some way to exploit this
common parameter.

You already are doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top