I have an abstract class as follows:
public abstract class Node
{
public abstract void run();
}
There are some child nodes that may have several properties as input and output. But all the operation is done just in run() method that each Node should implement. For example run() method of a Node that draws a line could be something like this:
public class LineNode : Node
{
public override void run()
{
line = new Line(a, b);
// draw line ...
}
}
The question I want to ask you is that, Which technology is better to use for defining input and outputs of these Nodes? Generics or attributes? With Attributes the LineNode would be something like this:
public class LineNode : Node
{
[Input]
public Point a;
[Input]
public Point b;
[Output]
public Line line;
public override void run()
{
line = new Line(a, b);
// draw line ...
}
}
[AttributeUsage(AttributeTargets.Field)]
public class Input : System.Attribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class Output : System.Attribute
{
}
Using Type parameters The Node would be something like this:
public class LineNode : Node
{
public Input<Point> a;
public Input<Point> b;
public Output<Line> line;
public override void run()
{
line = new Line(a, b);
// draw line ...
}
}
public class Input<T>
{
}
public class Output<T>
{
//
}
As you see I don't have any prior information about fields in the child classes. I just need a way to enumerate all the Inputs and Outputs of a child class in run-time (and if it is possible in compile time) using reflection. Which method better does fit this application?
Aucun commentaire:
Enregistrer un commentaire