I'm creating a library and in this library, It will contain Shapes more precisely Regular and Irregular Polygons, this library must allow the users to not only use my shapes but also in runtime be able to create his own.
At the moment I have a few shapes provided like so:
Polygon
|- PolygonRegular
|- Square
|- Circle
|- EquilateralTriangle implements Triangle
|- PolygonIrregular
|- Trapeze
|- IsoscelesTriangle implements Triangle
Now in this given scenario, let's say I as a user want to create my custom Polygon in this case "ScaleneTriangle" in which will further also implement the Triangle interface, my library must easily provide the tools necessary to create this "factory" to create shapes.
//Though I don't know the code, what I wanted to achieve, would be something very close to:
Point2D[] points = new Point2D[]{
new Point2D.Float(0f, 0f),
new Point2D.Float(0.25f, 0f),
new Point2D.Float(1f, 1f),
};
ContentFactory.create(PolygonIrregular.class, "ScaleneTriangle", points);
However, I have no idea How can I make a ContentFactory just like this, that create classes in runtime just like it was magic... I will also magically gonna have to create instances of these classes too.
To give about more understanding in case the problem wasn't very clarified: Imagine I'm a user, a canvas pop, draw a new shape. Confirms. A buttonRepresentation is created whit this new shape. Every time the user clicks in buttonRepresentation an element is created whit the shape.
Aucun commentaire:
Enregistrer un commentaire