Reputation: 3111
I have the following definitions for a class (I'm working with graphs, trying to work with them in a Generic Way).
public class SparseGraph<NodeType, EdgeType> : IGraphType<NodeType, EdgeType>
where NodeType : INode
where EdgeType : IEdge
{
...
}
public class ConcreteNode : INode
{
...
}
public class ConcreteEdge : IEdge
{
...
}
public class PathFinder<GraphType, NodeType, EdgeType> where GraphType<NodeType, EdgeType> : IGraphType<NodeType, EdgeType>
where NodeType : INode
where EdgeType : IEdge
{
...
...
}
Every time I have to instantiate the PathFinder class i.e. for a SparseGraph, I have to do it by using the following declaration:
var a = new PathFinder<SparseGraph<ConcreteNode, ConcreteEdge>, ConcreteNode, ConcreteEdge>()
The PathFinder class has a template of a template. Personally I dislike this kind of "redundancy" on this type instantiation. Is there any way to reduce the signature of the class PathFinder to something like "public class PathFinder"?
Upvotes: 1
Views: 65
Reputation: 16352
Inherit from
PathFinder<SparseGraph<ConcreteNode, ConcreteEdge>, ConcreteNode, ConcreteEdge>
ie.
public class NewClass : PathFinder<SparseGraph<ConcreteNode, ConcreteEdge>, ConcreteNode, ConcreteEdge>
Upvotes: 2
Reputation: 91
Personally I would implement more specific sub types for each of the common cases you are using, for example in the case of a "SparseGraph"
public class SparseGraphPathFinder : PathFinder<SparseGraph<ConcreteNode, ConcreteEdge>, ConcreteNode, ConcreteEdge>
{
}
Upvotes: 2