In my (OpenGL!) Java program, I need 3 types of Objects: Textures, Framebuffers, Screens. All three have some common characteristics (width, height, unique ID) but are also different in 1 fundamental way:
- Screens are only for output (render)
- Framebuffers can be read from and set up as surfaces for output
- Textures can only be read from (for the nitpickers: I know one can 'render to Texture' but only by attaching it first to an FBO, in which case my program treats it as an instance of a Framebuffer)
Were it C++ with its multiple inheritance, I'd have a base class 'Surface', then two derived classes 'InputSurface' and 'OutputSurface' , and have the Texture class extend InputSurface, the Screen OutputSurface, and the Framebuffer both.
Down to Earth- its Java, so I came up with the following monstrosity:
interface InputSurface
{
/**
* Return the width of this Surface.
*/
int getWidth();
/**
* Return the height of this Surface.
*/
int getHeight();
/**
* Take the underlying rectangle of pixels and bind this texture to OpenGL.
*/
boolean setAsInput();
}
abstract class Surface
{
/**
* Return the width of this Surface.
*
* @return width of the Object, in pixels.
*/
public int getWidth() {...}
/**
* Return the height of this Surface.
*
* @return height of the Object, in pixels.
*/
public int getHeight() {...}
}
public class Texture extends Surface implements InputSurface
{
/**
* Bind the underlying rectangle of pixels as a OpenGL Texture.
*/
public boolean setAsInput() {...}
}
abstract class OutputSurface extends Surface
{
abstract void setAsOutput();
}
public class Screen extends OutputSurface
{
setAsOutput() {...}
}
public class Framebuffer extends OutputSurface implements InputSurface
{
setAsInput() {...}
setAsOutput() {...}
}
(I need the InputSurface interface because later on I need to be able to accept both a Framebuffer and a Texture as inputs to generic methods like this
void renderFrom(InputSurface surface)
{
(...)
}
The above works, the only problem is it introduces a mess in the Javadoc-produced documentation. In its Texture and Framebuffer docs Javadoc essentially duplicates the 'getWidth/Height' metods, because it thinks there's one in Surface class and another in the InputSurface interface.
Here's the documentation it comes up with:
http://distorted.org/javadoc-library/org/distorted/library/DistortedTexture.html
Any advice?