I'm working on a 2D geometric game in which I have a base abstract class Figure from which different implementations inherit (e.g. CircleFigure, PolygonalFigure). I need an abstract method in Figure that checks whether two of these figures are intersecting, let its signature be public abstract boolean collision(Figure that).
The problem is that every pair of types of figures needs a different implementation of this method; i.e. for two circles I'd check that the sum of the two radii is less than the distance between the centers of the circles. But for a circle and a polygon, I'd use a completely different approach.
I'm aware of programming patterns and OOP concepts such as polymorphism which are appliable when we need to parametrize a method according to which subclass is executing it, but how can I parametrize according to which pair of classes call it?
Aucun commentaire:
Enregistrer un commentaire