I have several static βformβ classes that I use in my program, and since each of the static classes must perform the same operations, I wonder if there is a way to generalize the method call. If the classes were not static, I would just used the interface.
Here is the gist of my situation:
public static Triangle { public int getNumVerts() { return 3; } public bool isColliding() { return Triangle Collision Code Here } } public static Square { public int getNumVerts() { return 4; } public bool isColliding() { return Square Collision Code Here } }
What I would prefer to do is simply call Shape.getNumVerts() instead of my current switch statement:
switch (ShapeType) { case ShapeType.Triangle: Triangle.GetNumVerts(); case ShapeType.Square: Square.GetNumVerts(); }
I could just use polymorphism if singletones were used instead of static classes, but single numbers should be avoided, and I would need to pass a ton of links around so that I could process individual shapes as needed.
Is there a way to group these static classes, or is this switch statement as good as it is going to get?
source share