How to handle class dependency with interfaces and implementatons
- by lealand
I'm using ObjectAid with Eclipse to generate UML class diagrams for my latest Java project, and I currently have a handful of situations like this, where I have a dependency between two interfaces, as well as one of the implementations of one of the interfaces. Here, foo is the graphics library I'm using.
In the previous example, FooCanvas draws ITexture objects to the screen, and both FooCanvas and its interface, ICanvas, take ITexture objects as arguments to their methods.
The method in the canvas classes which cause this dependency is the following:
void drawTexture(ITexture texture, float x, float y);
Additionally, I tried a variation on the method signature using Java's generics:
<T extends ITexture> void drawTexture(T texture, float x, float y);
The result of this was a class diagram where the only dependencies where between the interfaces and the implementing classes, and no dependency by a canvas object on a texture. I'm not sure if this is more ideal or not.
Is the dependency of both the interface and implementation on another interface an expected pattern, or is it typical and/or possible to keep the implementation 'isolated' from its interfaces dependencies? Or is the generic method the ideal solution?