I have a class Point, that has a static type variable Visual. I made it static because: The type Visual contains method to draw points and lines between points, etc. The type Visual also creates a blank canvas each time a Visual object is instantiated. Since I need a group of points to be visualized on a single canvas, Visual is made a static singleton. My problem is I have a client class PointOp, that performs some operation with Point objects. I want all Point objects from PointOp instance 1 on a single canvas, and all Point objects from PointOp instance 2 on a single, different canvas. I can not achieve this by simply instantiate two PointOp objects. All Point objects from two instances are drawn on the same canvas. How may I solve this? Is there a way I can maintain different versions of the Visual object in different PointOp objects?
public class Point
{
static Visual visualize = null;
public void draw() // draw() method of Point
{
if (visualize == null)
visualize = new Visual();
visualize.draw(); // draw() method of type Visual evoked.
}
}
public class PointOp()
{
Point[] point;
public PointOp()
{
// Instantiate an array of Point objects for operation.
}
PointOp instance1 = new PointOp();
instance1.point[0].draw();
PointOp instance2 = new PointOp();
instance2.point[0].draw(); // Problem: all Points mixed on single canvas.
}