I have been developing a library with the help of another library.
So what I have set up here is two classes sub-classing the library's classes for additional functionality. The problem comes in when I want to be able to use the classes interchangeably in another class.
So I want to be able to pass these graphics into my object through the constructor as long as it is of type "super class".
The problem is, Rectangle and Circle have different property names for setting their position and in my object I need to set their position. I could check the type then cast, but then if someone wants to pass in a graphic like triangle, they'd have to edit the class to check for type triangle.
What I chose to do instead was create an interface ICenterable that my circle and rectangle class implement that requires a CenterX and CenterY property. Now anyone who has an ICenterable object can pass it into the object. This would be perfect, except now I have to choose whether the parameter being passed will be types as ICenterable or "super class". Once again, I could cast when needing certain functionality, but what if, for example, a "super class" is passed in that doesn't implement ICenterable. In the constructor I could check to make sure it's of both types or throw an error but that seems sloppy.
The best solution would be if I could state that the object being passed must implement ICenterable and extend "super class". I would do this through making a class that does both, but then my circle and rectangle classes wouldn't be able to extend that class because they need to extend Circle and Rectangle.
It seems like the more I do the worse it gets. Should I just accept it's not going to be how I want, forget the interface, and just check whether it's a rectangle, circle, and add more later if needed? Or is there a better way of doing it?